diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index e474899fb548ec..33131d80b35fad 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -701,7 +701,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, // Scale by the type size. unsigned TypeSize = AllocTypeSize.getFixedValue(); - LE = LE.mul(APInt(IndexSize, TypeSize), GEPOp->isInBounds()); + LE = LE.mul(APInt(IndexSize, TypeSize), GEPOp->hasNoUnsignedSignedWrap()); Decomposed.Offset += LE.Offset.sext(MaxIndexSize); APInt Scale = LE.Scale.sext(MaxIndexSize); diff --git a/llvm/test/Analysis/BasicAA/struct-geps.ll b/llvm/test/Analysis/BasicAA/struct-geps.ll index c7ca731697e49f..008d73ef44dcea 100644 --- a/llvm/test/Analysis/BasicAA/struct-geps.ll +++ b/llvm/test/Analysis/BasicAA/struct-geps.ll @@ -51,6 +51,17 @@ define void @test_not_inbounds(ptr %st, i64 %i, i64 %j, i64 %k) { ret void } +; It is sufficient to have nusw instead of inbounds. +; CHECK-LABEL: test_nusw +; CHECK: NoAlias: i32* %x, i32* %y +define void @test_nusw(ptr %st, i64 %i, i64 %j, i64 %k) { + %x = getelementptr nusw %struct, ptr %st, i64 %i, i32 0 + %y = getelementptr nusw %struct, ptr %st, i64 %j, i32 1 + load i32, ptr %x + load i32, ptr %y + ret void +} + ; CHECK-LABEL: test_in_array ; CHECK-DAG: MayAlias: [1 x %struct]* %st, i32* %x