summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/BasicAliasAnalysis.cpp
diff options
context:
space:
mode:
authorHal Finkel <hfinkel@anl.gov>2014-09-30 22:43:40 +0000
committerHal Finkel <hfinkel@anl.gov>2014-09-30 22:43:40 +0000
commitfd8631798970c5b527ec2ad071fe1582e5146ab5 (patch)
tree5d179a31335f22fa94cf84085c8270f195e81c3f /llvm/lib/Analysis/BasicAliasAnalysis.cpp
parent1cae849c04f343abb30817982633c369b6d90cda (diff)
downloadbcm5719-llvm-fd8631798970c5b527ec2ad071fe1582e5146ab5.tar.gz
bcm5719-llvm-fd8631798970c5b527ec2ad071fe1582e5146ab5.zip
[BasicAA] Make better use of zext and sign information
Two related things: 1. Fixes a bug when calculating the offset in GetLinearExpression. The code previously used zext to extend the offset, so negative offsets were converted to large positive ones. 2. Enhance aliasGEP to deduce that, if the difference between two GEP allocations is positive and all the variables that govern the offset are also positive (i.e. the offset is strictly after the higher base pointer), then locations that fit in the gap between the two base pointers are NoAlias. Patch by Nick White! llvm-svn: 218714
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/BasicAliasAnalysis.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 9cfd02c0218..f4052b9dbab 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -254,7 +254,10 @@ static Value *GetLinearExpression(Value *V, APInt &Scale, APInt &Offset,
Value *Result = GetLinearExpression(CastOp, Scale, Offset, Extension,
DL, Depth+1, AT, DT);
Scale = Scale.zext(OldWidth);
- Offset = Offset.zext(OldWidth);
+
+ // We have to sign-extend even if Extension == EK_ZeroExt as we can't
+ // decompose a sign extension (i.e. zext(x - 1) != zext(x) - zext(-1)).
+ Offset = Offset.sext(OldWidth);
return Result;
}
@@ -1055,8 +1058,26 @@ BasicAliasAnalysis::aliasGEP(const GEPOperator *GEP1, uint64_t V1Size,
// Grab the least significant bit set in any of the scales.
if (!GEP1VariableIndices.empty()) {
uint64_t Modulo = 0;
- for (unsigned i = 0, e = GEP1VariableIndices.size(); i != e; ++i)
+ bool AllPositive = true;
+ for (unsigned i = 0, e = GEP1VariableIndices.size(); i != e; ++i) {
+ const Value *V = GEP1VariableIndices[i].V;
Modulo |= (uint64_t)GEP1VariableIndices[i].Scale;
+
+ // If the variable's been zero-extended or begins with a zero then
+ // we know it's positive. regardless of whether the value is signed
+ // or unsigned.
+ bool SignKnownZero, SignKnownOne;
+ ComputeSignBit(
+ const_cast<Value *>(V),
+ SignKnownZero, SignKnownOne,
+ DL, 0, AT, nullptr, DT);
+ bool IsZExt = GEP1VariableIndices[i].Extension == EK_ZeroExt;
+ AllPositive &= IsZExt || SignKnownZero;
+
+ // If the Value is currently positive but could change in a cycle,
+ // then we can't guarantee it'll always br positive.
+ AllPositive &= isValueEqualInPotentialCycles(V, V);
+ }
Modulo = Modulo ^ (Modulo & (Modulo - 1));
// We can compute the difference between the two addresses
@@ -1066,6 +1087,12 @@ BasicAliasAnalysis::aliasGEP(const GEPOperator *GEP1, uint64_t V1Size,
if (V1Size != UnknownSize && V2Size != UnknownSize &&
ModOffset >= V2Size && V1Size <= Modulo - ModOffset)
return NoAlias;
+
+ // If we know all the variables are positive, then GEP1 >= GEP1BasePtr.
+ // If GEP1BasePtr > V2 (GEP1BaseOffset > 0) then we know the pointers
+ // don't alias if V2Size can fit in the gap between V2 and GEP1BasePtr.
+ if (AllPositive && GEP1BaseOffset > 0 && V2Size <= (uint64_t) GEP1BaseOffset)
+ return NoAlias;
}
// Statically, we can see that the base objects are the same, but the
OpenPOWER on IntegriCloud