[llvm] [BasicAA] Use nuw attribute of GEPs (PR #98608)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 6 07:14:44 PDT 2024
================
@@ -1233,6 +1232,32 @@ AliasResult BasicAAResult::aliasGEP(
}
}
+ // If the difference between pointers is Offset +<nuw> Indices (the variable
+ // indices all come from nuw GEPs) then we know that the addition does not
+ // wrap the pointer index type (add nuw) and the constant Offset is a lower
+ // bound on the distance between the pointers. We can then prove NoAlias via
+ // Offset u>= VLeftSize.
+ // + + +
+ // | BaseOffset | +<nuw> Indices |
+ // ---------------->|-------------------->|
+ // |-->VLeftSize | |-------> VRightSize
+ // LHS RHS
+ if (!DecompGEP1.VarIndices.empty() &&
+ llvm::all_of(DecompGEP1.VarIndices, [&](const VariableGEPIndex &V) {
+ return V.IsNegated == DecompGEP1.VarIndices.front().IsNegated;
+ })) {
+ APInt Off = DecompGEP1.Offset;
----------------
nikic wrote:
```suggestion
const APInt &Off = DecompGEP1.Offset;
```
https://github.com/llvm/llvm-project/pull/98608
More information about the llvm-commits
mailing list