Index: llvm/include/llvm/Analysis/BasicAliasAnalysis.h =================================================================== --- llvm/include/llvm/Analysis/BasicAliasAnalysis.h +++ llvm/include/llvm/Analysis/BasicAliasAnalysis.h @@ -118,6 +118,9 @@ APInt Scale; + // Context instruction to use when querying information about this index. + const Instruction *CxtI; + bool operator==(const VariableGEPIndex &Other) const { return V == Other.V && ZExtBits == Other.ZExtBits && SExtBits == Other.SExtBits && Scale == Other.Scale; Index: llvm/lib/Analysis/BasicAliasAnalysis.cpp =================================================================== --- llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -422,6 +422,7 @@ // Limit recursion depth to limit compile time in crazy cases. unsigned MaxLookup = MaxLookupSearchDepth; SearchTimes++; + const Instruction *CxtI = dyn_cast(V); unsigned MaxPointerSize = getMaxPointerSize(DL); DecomposedGEP Decomposed; @@ -584,7 +585,7 @@ Scale = adjustToPointerSize(Scale, PointerSize); if (!!Scale) { - VariableGEPIndex Entry = {Index, ZExtBits, SExtBits, Scale}; + VariableGEPIndex Entry = {Index, ZExtBits, SExtBits, Scale, CxtI}; Decomposed.VarIndices.push_back(Entry); } } @@ -1237,9 +1238,9 @@ // the Value this cycle may not hold in the next cycle. We'll just // give up if we can't determine conditions that hold for every cycle: const Value *V = DecompGEP1.VarIndices[i].V; + const Instruction *CxtI = DecompGEP1.VarIndices[i].CxtI; - KnownBits Known = - computeKnownBits(V, DL, 0, &AC, dyn_cast(GEP1), DT); + KnownBits Known = computeKnownBits(V, DL, 0, &AC, CxtI, DT); bool SignKnownZero = Known.isNonNegative(); bool SignKnownOne = Known.isNegative(); @@ -1767,7 +1768,7 @@ // If we didn't consume this entry, add it to the end of the Dest list. if (!!Scale) { - VariableGEPIndex Entry = {V, ZExtBits, SExtBits, -Scale}; + VariableGEPIndex Entry = {V, ZExtBits, SExtBits, -Scale, Src[i].CxtI}; Dest.push_back(Entry); } } Index: llvm/test/Analysis/BasicAA/assume-index-positive.ll =================================================================== --- llvm/test/Analysis/BasicAA/assume-index-positive.ll +++ llvm/test/Analysis/BasicAA/assume-index-positive.ll @@ -113,4 +113,20 @@ ret void } +define void @symmetry([0 x i8]* %ptr, i32 %a, i32 %b, i32 %c) { +; CHECK-LABEL: Function: symmetry +; CHECK: NoAlias: i8* %gep1, i8* %gep2 +; + %b.cmp = icmp slt i32 %b, 0 + call void @llvm.assume(i1 %b.cmp) + %gep1 = getelementptr [0 x i8], [0 x i8]* %ptr, i32 %a, i32 %b + call void @barrier() + %c.cmp = icmp sgt i32 %c, -1 + call void @llvm.assume(i1 %c.cmp) + %c.off = add nuw nsw i32 %c, 1 + %gep2 = getelementptr [0 x i8], [0 x i8]* %ptr, i32 %a, i32 %c.off + ret void +} + declare void @llvm.assume(i1 %cond) +declare void @barrier()