forked from OSchip/llvm-project
[basicaa] Recurse through a single phi input
BasicAA knows how to analyze phis, but to control compile time, we're fairly limited in doing so. This patch loosens that restriction just slightly when there is exactly one phi input (after discounting induction variable increments). The result of this is that we can handle more cases around nested and sibling loops with pointer induction variables. A few points to note. * This is deliberately extremely restrictive about recursing through at most one input of the phi. There's a known general problem with BasicAA sometimes hitting exponential compile time already, and this patch makes every effort not to compound the problem. Once the root issue is fixed, we can probably loosen the restrictions here a bit. * As seen in the test file, we're still missing cases which aren't *directly* based on phis (e.g. using the indvar increment). I believe this to be a separate problem and am going to explore this in another patch once this one lands. * As seen in the test file, this results in the unfortunate fact that using phivalues sometimes results in worse quality results. I believe this comes down to an oversight in how recursive phi detection was implemented for phivalues. I'm happy to tackle this in a follow up change. Differential Revision: https://reviews.llvm.org/D97401
This commit is contained in:
parent
2f37cdd569
commit
83ae49671d
|
@ -1368,13 +1368,19 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize,
|
|||
// If we don't have PhiInfo then just look at the operands of the phi itself
|
||||
// FIXME: Remove this once we can guarantee that we have PhiInfo always
|
||||
SmallPtrSet<Value *, 4> UniqueSrc;
|
||||
Value *OnePhi = nullptr;
|
||||
for (Value *PV1 : PN->incoming_values()) {
|
||||
if (isa<PHINode>(PV1))
|
||||
// If any of the source itself is a PHI, return MayAlias conservatively
|
||||
// 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;
|
||||
if (isa<PHINode>(PV1)) {
|
||||
if (OnePhi && OnePhi != PV1) {
|
||||
// To control potential compile time explosion, we choose to be
|
||||
// conserviate when we have more than one Phi input. It is important
|
||||
// that we handle the single phi case as that lets us handle LCSSA
|
||||
// phi nodes and (combined with the recursive phi handling) simple
|
||||
// pointer induction variable patterns.
|
||||
return MayAlias;
|
||||
}
|
||||
OnePhi = PV1;
|
||||
}
|
||||
|
||||
if (CheckForRecPhi(PV1))
|
||||
continue;
|
||||
|
@ -1382,6 +1388,11 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize,
|
|||
if (UniqueSrc.insert(PV1).second)
|
||||
V1Srcs.push_back(PV1);
|
||||
}
|
||||
|
||||
if (OnePhi && UniqueSrc.size() > 1)
|
||||
// Out of an abundance of caution, allow only the trivial lcssa and
|
||||
// recursive phi cases.
|
||||
return MayAlias;
|
||||
}
|
||||
|
||||
// If V1Srcs is empty then that means that the phi has no underlying non-phi
|
||||
|
|
|
@ -296,9 +296,9 @@ exit:
|
|||
; CHECK: NoAlias: i8* %a, i8* %p.base
|
||||
; CHECK: NoAlias: i8* %a, i8* %p.outer
|
||||
; CHECK: NoAlias: i8* %a, i8* %p.outer.next
|
||||
; CHECK: MayAlias: i8* %a, i8* %p.inner
|
||||
; NO-PHI-VALUES: NoAlias: i8* %a, i8* %p.inner
|
||||
; PHI-VALUES: MayAlias: i8* %a, i8* %p.inner
|
||||
; CHECK: NoAlias: i8* %a, i8* %p.inner.next
|
||||
; TODO: %p.inner does not alias %a
|
||||
define void @nested_loop3(i1 %c, i1 %c2, i8* noalias %p.base) {
|
||||
entry:
|
||||
%a = alloca i8
|
||||
|
@ -351,9 +351,9 @@ exit:
|
|||
; CHECK: NoAlias: i8* %a, i8* %p.base
|
||||
; CHECK: NoAlias: i8* %a, i8* %p1
|
||||
; CHECK: NoAlias: i8* %a, i8* %p1.next
|
||||
; CHECK: MayAlias: i8* %a, i8* %p2
|
||||
; NO-PHI-VALUES: NoAlias: i8* %a, i8* %p2
|
||||
; PHI-VALUES: MayAlias: i8* %a, i8* %p2
|
||||
; CHECK: NoAlias: i8* %a, i8* %p2.next
|
||||
; TODO: %p2 does not alias %a
|
||||
define void @sibling_loop2(i1 %c, i1 %c2, i8* noalias %p.base) {
|
||||
entry:
|
||||
%a = alloca i8
|
||||
|
|
Loading…
Reference in New Issue