Skip to content

Commit 2d39cb4

Browse files
authored
[BasicAA] Don't use MinAbsVarIndex = 1. (#72993)
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.
1 parent 42cd9ae commit 2d39cb4

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,9 +1230,6 @@ AliasResult BasicAAResult::aliasGEP(
12301230
const VariableGEPIndex &Var = DecompGEP1.VarIndices[0];
12311231
if (Var.Val.TruncBits == 0 &&
12321232
isKnownNonZero(Var.Val.V, DL, 0, &AC, Var.CxtI, DT)) {
1233-
// If V != 0, then abs(VarIndex) > 0.
1234-
MinAbsVarIndex = APInt(Var.Scale.getBitWidth(), 1);
1235-
12361233
// Check if abs(V*Scale) >= abs(Scale) holds in the presence of
12371234
// potentially wrapping math.
12381235
auto MultiplyByScaleNoWrap = [](const VariableGEPIndex &Var) {

llvm/test/Analysis/BasicAA/gep-modulo.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ define i8 @mul_may_overflow_var_nonzero_minabsvarindex_one_index(ptr %arr, i8 %x
326326
; CHECK-NEXT: PartialAlias (off 917): [2000 x i8]* %arr, i8* %gep.917
327327
; CHECK-NEXT: MayAlias: i8* %gep.917, i8* %gep.idx
328328
; CHECK-NEXT: MustAlias: [2000 x i8]* %arr, i8* %gep.0
329-
; CHECK-NEXT: NoAlias: i8* %gep.0, i8* %gep.idx
329+
; CHECK-NEXT: MayAlias: i8* %gep.0, i8* %gep.idx
330330
; CHECK-NEXT: NoAlias: i8* %gep.0, i8* %gep.917
331331
;
332332
load [2000 x i8], ptr %arr
@@ -362,10 +362,9 @@ define i8 @mul_nsw_var_nonzero_minabsvarindex_one_index(ptr %arr, i8 %x, i64 %v)
362362
ret i8 %l
363363
}
364364

365-
; FIXME: %gep and %p can alias.
366365
define i8 @test_pr72831_may_wrap(i64 %off) {
367366
; CHECK-LABEL: Function: test_pr72831_may_wrap: 2 pointers, 0 call sites
368-
; CHECK-NEXT: NoAlias: i8* %gep, i8* %p
367+
; CHECK-NEXT: MayAlias: i8* %gep, i8* %p
369368
entry:
370369
%p = alloca [2 x i8], align 1
371370
%ext = zext i1 false to i64

0 commit comments

Comments
 (0)