[llvm] r369795 - Fix a bug in just submitted rL369789
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 23 11:27:57 PDT 2019
Author: reames
Date: Fri Aug 23 11:27:57 2019
New Revision: 369795
URL: http://llvm.org/viewvc/llvm-project?rev=369795&view=rev
Log:
Fix a bug in just submitted rL369789
Started implementing the vector case and realized the scalar case hadn't handled the GEP producing a different type than the base correctly. It's entertaining seeing what slips through review when we're focused on the 'hard' parts. :(
Also adding an extra vector test as it happened to be in workspace and wasn't worth separating.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/gep-inbounds-null.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=369795&r1=369794&r2=369795&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Fri Aug 23 11:27:57 2019
@@ -914,7 +914,10 @@ Instruction *InstCombiner::foldGEPICmp(G
// 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.
Modified: llvm/trunk/test/Transforms/InstCombine/gep-inbounds-null.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/gep-inbounds-null.ll?rev=369795&r1=369794&r2=369795&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/gep-inbounds-null.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/gep-inbounds-null.ll Fri Aug 23 11:27:57 2019
@@ -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.
@@ -154,6 +167,19 @@ entry:
ret i1 %cnd
}
+
+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.
More information about the llvm-commits
mailing list