[llvm-branch-commits] [llvm] d716eab - [BasicAA] Make non-equal index handling simpler to extend (NFC)
Nikita Popov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Dec 12 06:04:59 PST 2020
Author: Nikita Popov
Date: 2020-12-12T15:00:47+01:00
New Revision: d716eab197abec0b9aab4a76cd1a52b248b8c3b1
URL: https://github.com/llvm/llvm-project/commit/d716eab197abec0b9aab4a76cd1a52b248b8c3b1
DIFF: https://github.com/llvm/llvm-project/commit/d716eab197abec0b9aab4a76cd1a52b248b8c3b1.diff
LOG: [BasicAA] Make non-equal index handling simpler to extend (NFC)
Added:
Modified:
llvm/lib/Analysis/BasicAliasAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index caf540bb7fd9..9ba61ad64178 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1285,24 +1285,27 @@ AliasResult BasicAAResult::aliasGEP(
(-DecompGEP1.Offset).uge(V1Size.getValue()))
return NoAlias;
- // Try to determine whether the variable part of the GEP is non-zero, in
- // which case we can add/subtract a minimum scale from the offset.
- // TODO: Currently this handles the case of Scale*V0-Scale*V1 where V0!=V1.
- // We could also handle Scale*V0 where V0!=0.
- if (V1Size.hasValue() && V2Size.hasValue() &&
- DecompGEP1.VarIndices.size() == 2) {
- const VariableGEPIndex &Var0 = DecompGEP1.VarIndices[0];
- const VariableGEPIndex &Var1 = DecompGEP1.VarIndices[1];
- // Check that VisitedPhiBBs is empty, to avoid reasoning about inequality
- // of values across loop iterations.
- if (Var0.Scale == -Var1.Scale && Var0.ZExtBits == Var1.ZExtBits &&
- Var0.SExtBits == Var1.SExtBits && VisitedPhiBBs.empty() &&
- isKnownNonEqual(Var0.V, Var1.V, DL)) {
- // If the indexes are not equal, the actual offset will have at least
- // Scale or -Scale added to it.
- APInt Scale = Var0.Scale.abs();
- APInt OffsetLo = DecompGEP1.Offset - Scale;
- APInt OffsetHi = DecompGEP1.Offset + Scale;
+ if (V1Size.hasValue() && V2Size.hasValue()) {
+ // Try to determine whether abs(VarIndex) > 0.
+ Optional<APInt> MinAbsVarIndex;
+ // TODO: Could handle single non-zero index as well.
+ if (DecompGEP1.VarIndices.size() == 2) {
+ // VarIndex = Scale*V0 + (-Scale)*V1.
+ // If V0 != V1 then abs(VarIndex) >= abs(Scale).
+ // Check that VisitedPhiBBs is empty, to avoid reasoning about
+ // inequality of values across loop iterations.
+ const VariableGEPIndex &Var0 = DecompGEP1.VarIndices[0];
+ const VariableGEPIndex &Var1 = DecompGEP1.VarIndices[1];
+ if (Var0.Scale == -Var1.Scale && Var0.ZExtBits == Var1.ZExtBits &&
+ Var0.SExtBits == Var1.SExtBits && VisitedPhiBBs.empty() &&
+ isKnownNonEqual(Var0.V, Var1.V, DL))
+ MinAbsVarIndex = Var0.Scale.abs();
+ }
+
+ if (MinAbsVarIndex) {
+ // The constant offset will have added at least +/-MinAbsVarIndex to it.
+ APInt OffsetLo = DecompGEP1.Offset - *MinAbsVarIndex;
+ APInt OffsetHi = DecompGEP1.Offset + *MinAbsVarIndex;
// Check that an access at OffsetLo or lower, and an access at OffsetHi
// or higher both do not alias.
if (OffsetLo.isNegative() && (-OffsetLo).uge(V1Size.getValue()) &&
More information about the llvm-branch-commits
mailing list