summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp5
-rw-r--r--llvm/test/Transforms/InstCombine/gep-inbounds-null.ll26
2 files changed, 30 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 2bc21292b13..4e161d612cf 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -914,7 +914,10 @@ Instruction *InstCombiner::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
// In general, we're allowed to make values less poison (i.e. remove
// sources of full UB), so in this case, we just select between the two
// non-poison cases (1 and 4 above).
- return new ICmpInst(Cond, GEPLHS->getPointerOperand(), RHS);
+ auto *Base = GEPLHS->getPointerOperand();
+ return new ICmpInst(Cond, Base,
+ ConstantExpr::getBitCast(cast<Constant>(RHS),
+ Base->getType()));
} else if (GEPOperator *GEPRHS = dyn_cast<GEPOperator>(RHS)) {
// If the base pointers are different, but the indices are the same, just
// compare the base pointer.
diff --git a/llvm/test/Transforms/InstCombine/gep-inbounds-null.ll b/llvm/test/Transforms/InstCombine/gep-inbounds-null.ll
index c369c1e513b..544f9a3f2e3 100644
--- a/llvm/test/Transforms/InstCombine/gep-inbounds-null.ll
+++ b/llvm/test/Transforms/InstCombine/gep-inbounds-null.ll
@@ -102,6 +102,19 @@ entry:
ret <2 x i1> %cnd
}
+define <2 x i1> @test_vector_both(<2 x i8*> %base, <2 x i64> %idx) {
+; CHECK-LABEL: @test_vector_both(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, <2 x i8*> [[BASE:%.*]], <2 x i64> [[IDX:%.*]]
+; CHECK-NEXT: [[CND:%.*]] = icmp eq <2 x i8*> [[GEP]], zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[CND]]
+;
+entry:
+ %gep = getelementptr inbounds i8, <2 x i8*> %base, <2 x i64> %idx
+ %cnd = icmp eq <2 x i8*> %gep, zeroinitializer
+ ret <2 x i1> %cnd
+}
+
;; These two show instsimplify's reasoning getting to the non-zero offsets
;; before instcombine does.
@@ -155,6 +168,19 @@ entry:
}
+define i1 @test_index_type([10 x i8]* %base, i64 %idx) {
+; CHECK-LABEL: @test_index_type(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CND:%.*]] = icmp eq [10 x i8]* [[BASE:%.*]], null
+; CHECK-NEXT: ret i1 [[CND]]
+;
+entry:
+ %gep = getelementptr inbounds [10 x i8], [10 x i8]* %base, i64 %idx, i64 %idx
+ %cnd = icmp eq i8* %gep, null
+ ret i1 %cnd
+}
+
+
;; Finally, some negative tests for sanity checking.
define i1 @neq_noinbounds(i8* %base, i64 %idx) {
OpenPOWER on IntegriCloud