[llvm] d56d808 - [BasicAA] Check nusw instead of inbounds

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 6 05:38:57 PDT 2024


Author: Nikita Popov
Date: 2024-08-06T14:38:49+02:00
New Revision: d56d808fdcae06af5d704b42b0c237d93aee3857

URL: https://github.com/llvm/llvm-project/commit/d56d808fdcae06af5d704b42b0c237d93aee3857
DIFF: https://github.com/llvm/llvm-project/commit/d56d808fdcae06af5d704b42b0c237d93aee3857.diff

LOG: [BasicAA] Check nusw instead of inbounds

For the offset scaling, this is sufficient to guarantee nsw. The
other checks for inbounds in this file do need proper inbounds.

Added: 
    

Modified: 
    llvm/lib/Analysis/BasicAliasAnalysis.cpp
    llvm/test/Analysis/BasicAA/struct-geps.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index e474899fb548e..33131d80b35fa 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 c7ca731697e49..008d73ef44dce 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


        


More information about the llvm-commits mailing list