// 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.
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.
}
+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) {