aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2007-09-06 01:10:22 +0000
committerNick Lewycky <nicholas@mxc.ca>2007-09-06 01:10:22 +0000
commit5a5ff9d7dfdedb8838c6bd7f69ab952c37d624d4 (patch)
treeaedd3a8f3b8d82af4181300fe317ad93e1242072
parentdd199d29b781bc713462f1255b63d3f153bfd9e9 (diff)
When the two operands of an icmp are equal, there are five possible predicates
that would make the icmp true. Fixes PR1637. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41740 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp4
-rw-r--r--test/Transforms/InstCombine/2007-09-05-EqualGEP.ll10
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 9db10340a1..58eb3bc275 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -4563,7 +4563,9 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
if (NumDifferences == 0) // SAME GEP?
return ReplaceInstUsesWith(I, // No comparison is needed here.
ConstantInt::get(Type::Int1Ty,
- Cond == ICmpInst::ICMP_EQ));
+ Cond == ICmpInst::ICMP_EQ ||
+ Cond == ICmpInst::ICMP_ULE || Cond == ICmpInst::ICMP_UGE ||
+ Cond == ICmpInst::ICMP_SLE || Cond == ICmpInst::ICMP_SGE));
else if (NumDifferences == 1) {
Value *LHSV = GEPLHS->getOperand(DiffOperand);
Value *RHSV = GEPRHS->getOperand(DiffOperand);
diff --git a/test/Transforms/InstCombine/2007-09-05-EqualGEP.ll b/test/Transforms/InstCombine/2007-09-05-EqualGEP.ll
new file mode 100644
index 0000000000..77bae78ccd
--- /dev/null
+++ b/test/Transforms/InstCombine/2007-09-05-EqualGEP.ll
@@ -0,0 +1,10 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {ret i1 true}
+; PR1637
+
+define i1 @f(i8* %arr) {
+ %X = getelementptr i8* %arr, i32 1
+ %Y = getelementptr i8* %arr, i32 1
+ %test = icmp uge i8* %X, %Y
+ ret i1 %test
+}
+