summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/BasicAliasAnalysis.cpp
diff options
context:
space:
mode:
authorGerolf Hoflehner <ghoflehner@apple.com>2016-10-22 02:41:39 +0000
committerGerolf Hoflehner <ghoflehner@apple.com>2016-10-22 02:41:39 +0000
commit9e2afa8bd79b1cc3a6be15856371aa5f43f37d22 (patch)
treeeacfa5f7e3280bbce75dcb5dd39bdeccb04bd339 /llvm/lib/Analysis/BasicAliasAnalysis.cpp
parent6294a768e5b42dec43a6176c2d3f09038af78b9d (diff)
downloadbcm5719-llvm-9e2afa8bd79b1cc3a6be15856371aa5f43f37d22.tar.gz
bcm5719-llvm-9e2afa8bd79b1cc3a6be15856371aa5f43f37d22.zip
[BasicAA] Fix - missed alias in GEP expressions
In BasicAA GEP operand values get adjusted ("wrap-around") based on the pointersize. Otherwise, in non-64b modes, AA could report false negatives. However, a wrap-around is valid only for a fully evaluated expression. It had been introduced to fix an alias problem in http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160118/326163.html. This commit restricts the wrap-around to constant gep operands only where the value is known at compile-time. llvm-svn: 284908
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/BasicAliasAnalysis.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index a28db6c269e..8b5f323ee21 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -409,6 +409,8 @@ bool BasicAAResult::DecomposeGEPExpression(const Value *V,
// Walk the indices of the GEP, accumulating them into BaseOff/VarIndices.
gep_type_iterator GTI = gep_type_begin(GEPOp);
unsigned PointerSize = DL.getPointerSizeInBits(AS);
+ // Assume all GEP operands are constants until proven otherwise.
+ bool GepHasConstantOffset = true;
for (User::const_op_iterator I = GEPOp->op_begin() + 1, E = GEPOp->op_end();
I != E; ++I) {
const Value *Index = *I;
@@ -433,6 +435,8 @@ bool BasicAAResult::DecomposeGEPExpression(const Value *V,
continue;
}
+ GepHasConstantOffset = false;
+
uint64_t Scale = DL.getTypeAllocSize(*GTI);
unsigned ZExtBits = 0, SExtBits = 0;
@@ -458,7 +462,7 @@ bool BasicAAResult::DecomposeGEPExpression(const Value *V,
// A[x][x] -> x*16 + x*4 -> x*20
// This also ensures that 'x' only appears in the index list once.
for (unsigned i = 0, e = Decomposed.VarIndices.size(); i != e; ++i) {
- if (Decomposed.VarIndices[i].V == Index &&
+ if (Decomposed.VarIndices[i].V == Index &&
Decomposed.VarIndices[i].ZExtBits == ZExtBits &&
Decomposed.VarIndices[i].SExtBits == SExtBits) {
Scale += Decomposed.VarIndices[i].Scale;
@@ -479,10 +483,12 @@ bool BasicAAResult::DecomposeGEPExpression(const Value *V,
}
// Take care of wrap-arounds
- Decomposed.StructOffset =
- adjustToPointerSize(Decomposed.StructOffset, PointerSize);
- Decomposed.OtherOffset =
- adjustToPointerSize(Decomposed.OtherOffset, PointerSize);
+ if (GepHasConstantOffset) {
+ Decomposed.StructOffset =
+ adjustToPointerSize(Decomposed.StructOffset, PointerSize);
+ Decomposed.OtherOffset =
+ adjustToPointerSize(Decomposed.OtherOffset, PointerSize);
+ }
// Analyze the base pointer next.
V = GEPOp->getOperand(0);
OpenPOWER on IntegriCloud