Index: lib/Transforms/InstCombine/InstCombineCompares.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCompares.cpp +++ lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -618,7 +618,7 @@ // Look through bitcasts and addrspacecasts. We do not however want to remove // 0 GEPs. if (!isa(RHS)) - RHS = RHS->stripPointerCasts(); + RHS = RHS->stripPointerCasts(/*LookThroughNoAlias*/true); Value *PtrBase = GEPLHS->getOperand(0); if (PtrBase == RHS && GEPLHS->isInBounds()) { @@ -657,8 +657,8 @@ if (GEPLHS->isInBounds() && GEPRHS->isInBounds() && (GEPLHS->hasAllConstantIndices() || GEPLHS->hasOneUse()) && (GEPRHS->hasAllConstantIndices() || GEPRHS->hasOneUse()) && - PtrBase->stripPointerCasts() == - GEPRHS->getOperand(0)->stripPointerCasts()) { + PtrBase->stripPointerCasts(/*LookThroughNoAlias*/true) == + GEPRHS->getOperand(0)->stripPointerCasts(true)) { Value *LOffset = EmitGEPOffset(GEPLHS); Value *ROffset = EmitGEPOffset(GEPRHS); Index: test/Transforms/InstCombine/icmp.ll =================================================================== --- test/Transforms/InstCombine/icmp.ll +++ test/Transforms/InstCombine/icmp.ll @@ -658,6 +658,20 @@ ; CHECK-NEXT: ret i1 } +define i1 @test60a(i8* %foo, i64 %i, i64 %j) { + %bit = bitcast i8* %foo to i32* + %gep1 = getelementptr inbounds i32, i32* %bit, i64 %i + %fooa = call i8* @llvm.noalias.p0i8(i8* %foo, metadata !1) + %gep2 = getelementptr inbounds i8, i8* %fooa, i64 %j + %cast1 = bitcast i32* %gep1 to i8* + %cmp = icmp ult i8* %cast1, %gep2 + ret i1 %cmp +; CHECK-LABEL: @test60a( +; CHECK-NEXT: %gep1.idx = shl nuw i64 %i, 2 +; CHECK-NEXT: icmp slt i64 %gep1.idx, %j +; CHECK-NEXT: ret i1 +} + define i1 @test60_as1(i8 addrspace(1)* %foo, i64 %i, i64 %j) { %bit = bitcast i8 addrspace(1)* %foo to i32 addrspace(1)* %gep1 = getelementptr inbounds i32, i32 addrspace(1)* %bit, i64 %i @@ -1603,3 +1617,9 @@ %s = select i1 %cmp, i32 10000, i32 0 ret i32 %s } + +declare i8* @llvm.noalias.p0i8(i8*, metadata) nounwind + +!0 = !{!0, !"some domain"} +!1 = !{!1, !0, !"some scope"} +