mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-09 17:41:10 +00:00
Another BasicAA fix. If a value does not alias a GEP's base pointer, then it
cannot alias the GEP. GEP pointer alias rule states this clearly: A pointer value formed from a getelementptr instruction is associated with the addresses associated with the first operand of the getelementptr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84079 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
df199f11c6
commit
681a33e26d
@ -428,8 +428,15 @@ BasicAliasAnalysis::aliasGEP(const Value *V1, unsigned V1Size,
|
|||||||
SmallVector<Value*, 16> GEPOperands;
|
SmallVector<Value*, 16> GEPOperands;
|
||||||
const Value *BasePtr = GetGEPOperands(V1, GEPOperands);
|
const Value *BasePtr = GetGEPOperands(V1, GEPOperands);
|
||||||
|
|
||||||
AliasResult R = aliasCheck(BasePtr, V1Size, V2, V2Size);
|
AliasResult R = aliasCheck(BasePtr, ~0U, V2, V2Size);
|
||||||
if (R == MustAlias) {
|
if (R != MustAlias)
|
||||||
|
// If V2 may alias GEP base pointer, conservatively returns MayAlias.
|
||||||
|
// If V2 is known not to alias GEP base pointer, then the two values
|
||||||
|
// cannot alias per GEP semantics: "A pointer value formed from a
|
||||||
|
// getelementptr instruction is associated with the addresses associated
|
||||||
|
// with the first operand of the getelementptr".
|
||||||
|
return R;
|
||||||
|
|
||||||
// If there is at least one non-zero constant index, we know they cannot
|
// If there is at least one non-zero constant index, we know they cannot
|
||||||
// alias.
|
// alias.
|
||||||
bool ConstantFound = false;
|
bool ConstantFound = false;
|
||||||
@ -463,8 +470,7 @@ BasicAliasAnalysis::aliasGEP(const Value *V1, unsigned V1Size,
|
|||||||
for (unsigned i = 0; i != GEPOperands.size(); ++i)
|
for (unsigned i = 0; i != GEPOperands.size(); ++i)
|
||||||
if (!isa<ConstantInt>(GEPOperands[i]))
|
if (!isa<ConstantInt>(GEPOperands[i]))
|
||||||
GEPOperands[i] = Constant::getNullValue(GEPOperands[i]->getType());
|
GEPOperands[i] = Constant::getNullValue(GEPOperands[i]->getType());
|
||||||
int64_t Offset =
|
int64_t Offset = TD->getIndexedOffset(BasePtr->getType(),
|
||||||
TD->getIndexedOffset(BasePtr->getType(),
|
|
||||||
&GEPOperands[0],
|
&GEPOperands[0],
|
||||||
GEPOperands.size());
|
GEPOperands.size());
|
||||||
|
|
||||||
@ -472,7 +478,6 @@ BasicAliasAnalysis::aliasGEP(const Value *V1, unsigned V1Size,
|
|||||||
return NoAlias;
|
return NoAlias;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return MayAlias;
|
return MayAlias;
|
||||||
}
|
}
|
||||||
@ -492,7 +497,9 @@ BasicAliasAnalysis::aliasPHI(const PHINode *PN, unsigned PNSize,
|
|||||||
Value *PV1 = PN->getIncomingValue(i);
|
Value *PV1 = PN->getIncomingValue(i);
|
||||||
if (isa<PHINode>(PV1))
|
if (isa<PHINode>(PV1))
|
||||||
// If any of the source itself is a PHI, return MayAlias conservatively
|
// If any of the source itself is a PHI, return MayAlias conservatively
|
||||||
// to avoid compile time explosion.
|
// to avoid compile time explosion. The worst possible case is if both
|
||||||
|
// sides are PHI nodes. In which case, this is O(m x n) time where 'm'
|
||||||
|
// and 'n' are the number of PHI sources.
|
||||||
return MayAlias;
|
return MayAlias;
|
||||||
if (UniqueSrc.insert(PV1))
|
if (UniqueSrc.insert(PV1))
|
||||||
V1Srcs.push_back(PV1);
|
V1Srcs.push_back(PV1);
|
||||||
|
30
test/Analysis/BasicAA/2009-10-13-GEP-BaseNoAlias.ll
Normal file
30
test/Analysis/BasicAA/2009-10-13-GEP-BaseNoAlias.ll
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
; RUN: opt < %s -aa-eval -print-all-alias-modref-info -disable-output |& grep {NoAlias:.*%P,.*@Z}
|
||||||
|
; If GEP base doesn't alias Z, then GEP doesn't alias Z.
|
||||||
|
; rdar://7282591
|
||||||
|
|
||||||
|
@Y = common global i32 0
|
||||||
|
@Z = common global i32 0
|
||||||
|
|
||||||
|
define void @foo(i32 %cond) nounwind ssp {
|
||||||
|
entry:
|
||||||
|
%a = alloca i32
|
||||||
|
%tmp = icmp ne i32 %cond, 0
|
||||||
|
br i1 %tmp, label %bb, label %bb1
|
||||||
|
|
||||||
|
bb:
|
||||||
|
%b = getelementptr i32* %a, i32 0
|
||||||
|
br label %bb2
|
||||||
|
|
||||||
|
bb1:
|
||||||
|
br label %bb2
|
||||||
|
|
||||||
|
bb2:
|
||||||
|
%P = phi i32* [ %b, %bb ], [ @Y, %bb1 ]
|
||||||
|
%tmp1 = load i32* @Z, align 4
|
||||||
|
store i32 123, i32* %P, align 4
|
||||||
|
%tmp2 = load i32* @Z, align 4
|
||||||
|
br label %return
|
||||||
|
|
||||||
|
return:
|
||||||
|
ret void
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user