Skip to content

Commit d56d808

Browse files
committed
[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.
1 parent 617cf8a commit d56d808

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
701701

702702
// Scale by the type size.
703703
unsigned TypeSize = AllocTypeSize.getFixedValue();
704-
LE = LE.mul(APInt(IndexSize, TypeSize), GEPOp->isInBounds());
704+
LE = LE.mul(APInt(IndexSize, TypeSize), GEPOp->hasNoUnsignedSignedWrap());
705705
Decomposed.Offset += LE.Offset.sext(MaxIndexSize);
706706
APInt Scale = LE.Scale.sext(MaxIndexSize);
707707

llvm/test/Analysis/BasicAA/struct-geps.ll

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ define void @test_not_inbounds(ptr %st, i64 %i, i64 %j, i64 %k) {
5151
ret void
5252
}
5353

54+
; It is sufficient to have nusw instead of inbounds.
55+
; CHECK-LABEL: test_nusw
56+
; CHECK: NoAlias: i32* %x, i32* %y
57+
define void @test_nusw(ptr %st, i64 %i, i64 %j, i64 %k) {
58+
%x = getelementptr nusw %struct, ptr %st, i64 %i, i32 0
59+
%y = getelementptr nusw %struct, ptr %st, i64 %j, i32 1
60+
load i32, ptr %x
61+
load i32, ptr %y
62+
ret void
63+
}
64+
5465
; CHECK-LABEL: test_in_array
5566

5667
; CHECK-DAG: MayAlias: [1 x %struct]* %st, i32* %x

0 commit comments

Comments
 (0)