Skip to content

[BasicAA] Don't use MinAbsVarIndex = 1. #72993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2023
Merged

Conversation

fhahn
Copy link
Contributor

@fhahn fhahn commented Nov 21, 2023

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 #72831.

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 llvm#72831.
@fhahn fhahn requested a review from alinas November 21, 2023 13:44
@fhahn fhahn requested a review from nikic as a code owner November 21, 2023 13:44
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Nov 21, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2023

@llvm/pr-subscribers-llvm-analysis

Author: Florian Hahn (fhahn)

Changes

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 #72831.


Full diff: https://github.com/llvm/llvm-project/pull/72993.diff

2 Files Affected:

  • (modified) llvm/lib/Analysis/BasicAliasAnalysis.cpp (-3)
  • (modified) llvm/test/Analysis/BasicAA/gep-modulo.ll (+2-2)
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

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fhahn fhahn merged commit 2d39cb4 into llvm:main Nov 21, 2023
@fhahn fhahn deleted the basicaa-wrapping-1 branch November 21, 2023 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong code at -O2 on x86_64-linux_gnu(recent regression)
3 participants