From: Philip Reames Date: Fri, 23 Aug 2019 18:27:57 +0000 (+0000) Subject: Fix a bug in just submitted rL369789 X-Git-Tag: llvmorg-11-init~10988 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9cb059fdcc03e2144fa9aac0bfbb49c0d5d7efe2;p=platform%2Fupstream%2Fllvm.git 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. llvm-svn: 369795 --- diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 2bc21292b137..4e161d612cfe 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(RHS), + Base->getType())); } else if (GEPOperator *GEPRHS = dyn_cast(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 c369c1e513bc..544f9a3f2e38 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) {