Skip to content

Commit

Permalink
[BasicAA] Check nusw instead of inbounds
Browse files Browse the repository at this point in the history
For the offset scaling, this is sufficient to guarantee nsw. The
other checks for inbounds in this file do need proper inbounds.
  • Loading branch information
nikic committed Aug 6, 2024
1 parent 617cf8a commit d56d808
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/BasicAliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions llvm/test/Analysis/BasicAA/struct-geps.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d56d808

Please sign in to comment.