[llvm] [BasicAA] Don't use MinAbsVarIndex = 1. (PR #72993)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 21 06:03:00 PST 2023


https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/72993

>From 075c0f0956c06e54e7d01b3651fa70c063a96489 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Tue, 21 Nov 2023 13:40:49 +0000
Subject: [PATCH 1/2] [BasicAA] Don't use MinAbsVarIndex = 1.

The current code incorrectly assumed that the absolute variable index
needs to be at least 1, if the variable is != 0. This is incorrect, in
case multiplying with Scale wraps.

The code below already checks for wrapping properly, so just remove the
incorrect assignment.

Fixes https://github.com/llvm/llvm-project/issues/72831.
---
 llvm/lib/Analysis/BasicAliasAnalysis.cpp | 3 ---
 llvm/test/Analysis/BasicAA/gep-modulo.ll | 4 ++--
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index bf766ee67bb35bf..4d2f81ea4cfca66 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1230,9 +1230,6 @@ AliasResult BasicAAResult::aliasGEP(
     const VariableGEPIndex &Var = DecompGEP1.VarIndices[0];
     if (Var.Val.TruncBits == 0 &&
         isKnownNonZero(Var.Val.V, DL, 0, &AC, Var.CxtI, DT)) {
-      // If V != 0, then abs(VarIndex) > 0.
-      MinAbsVarIndex = APInt(Var.Scale.getBitWidth(), 1);
-
       // Check if abs(V*Scale) >= abs(Scale) holds in the presence of
       // potentially wrapping math.
       auto MultiplyByScaleNoWrap = [](const VariableGEPIndex &Var) {
diff --git a/llvm/test/Analysis/BasicAA/gep-modulo.ll b/llvm/test/Analysis/BasicAA/gep-modulo.ll
index a84e0fc53cdc096..05df55079e854a7 100644
--- a/llvm/test/Analysis/BasicAA/gep-modulo.ll
+++ b/llvm/test/Analysis/BasicAA/gep-modulo.ll
@@ -326,7 +326,7 @@ define i8 @mul_may_overflow_var_nonzero_minabsvarindex_one_index(ptr %arr, i8 %x
 ; CHECK-NEXT:  PartialAlias (off 917): [2000 x i8]* %arr, i8* %gep.917
 ; CHECK-NEXT:  MayAlias: i8* %gep.917, i8* %gep.idx
 ; CHECK-NEXT:  MustAlias: [2000 x i8]* %arr, i8* %gep.0
-; CHECK-NEXT:  NoAlias: i8* %gep.0, i8* %gep.idx
+; CHECK-NEXT:  MayAlias: i8* %gep.0, i8* %gep.idx
 ; CHECK-NEXT:  NoAlias: i8* %gep.0, i8* %gep.917
 ;
   load [2000 x i8], ptr %arr
@@ -365,7 +365,7 @@ define i8 @mul_nsw_var_nonzero_minabsvarindex_one_index(ptr %arr, i8 %x, i64 %v)
 ; FIXME: %gep and %p can alias.
 define i8 @test_pr72831_may_wrap(i64 %off) {
 ; CHECK-LABEL: Function: test_pr72831_may_wrap: 2 pointers, 0 call sites
-; CHECK-NEXT:  NoAlias:    i8* %gep, i8* %p
+; CHECK-NEXT:  MayAlias:    i8* %gep, i8* %p
 entry:
   %p = alloca [2 x i8], align 1
   %ext = zext i1 false to i64

>From cc375187b81f8b85cdaed0303d9038d3a4a39b3e Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Tue, 21 Nov 2023 14:02:13 +0000
Subject: [PATCH 2/2] drop fixme

---
 llvm/test/Analysis/BasicAA/gep-modulo.ll | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/test/Analysis/BasicAA/gep-modulo.ll b/llvm/test/Analysis/BasicAA/gep-modulo.ll
index 05df55079e854a7..159aaf94039d3ca 100644
--- a/llvm/test/Analysis/BasicAA/gep-modulo.ll
+++ b/llvm/test/Analysis/BasicAA/gep-modulo.ll
@@ -362,7 +362,6 @@ define i8 @mul_nsw_var_nonzero_minabsvarindex_one_index(ptr %arr, i8 %x, i64 %v)
   ret i8 %l
 }
 
-; FIXME: %gep and %p can alias.
 define i8 @test_pr72831_may_wrap(i64 %off) {
 ; CHECK-LABEL: Function: test_pr72831_may_wrap: 2 pointers, 0 call sites
 ; CHECK-NEXT:  MayAlias:    i8* %gep, i8* %p



More information about the llvm-commits mailing list