Skip to content

Commit d337d11

Browse files
committed
[BasicAA][LAA] Don't use same-block phis in cross iteration mode
In 4de3184 we exposed BasicAA's cross-iteration mode for use in LAA, so we can handle selects with equal conditions correctly (where the select condition is not actually equal across iterations). However, if we replace the selects with equivalent phis, the issue still exists. In the phi case, we effectively still have an assumption that the condition(s) that control which phi arg is used will be the same across iterations. Fix this by disabling this case in cross-iteration mode.
1 parent 681939e commit d337d11

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,9 +1447,10 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize,
14471447
return AliasResult::NoAlias;
14481448
// If the values are PHIs in the same block, we can do a more precise
14491449
// as well as efficient check: just check for aliases between the values
1450-
// on corresponding edges.
1450+
// on corresponding edges. Don't do this if we are analyzing across
1451+
// iterations, as we may pick a different phi entry in different iterations.
14511452
if (const PHINode *PN2 = dyn_cast<PHINode>(V2))
1452-
if (PN2->getParent() == PN->getParent()) {
1453+
if (PN2->getParent() == PN->getParent() && !AAQI.MayBeCrossIteration) {
14531454
std::optional<AliasResult> Alias;
14541455
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
14551456
AliasResult ThisAlias = AAQI.AAR.alias(

llvm/test/Analysis/LoopAccessAnalysis/select-dependence.ll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ exit:
4444
define void @test_phi(ptr noalias %x, ptr noalias %y, ptr noalias %z) {
4545
; CHECK-LABEL: 'test_phi'
4646
; CHECK-NEXT: loop:
47-
; CHECK-NEXT: Memory dependences are safe
47+
; CHECK-NEXT: Report: unsafe dependent memory operations in loop. Use #pragma clang loop distribute(enable) to allow loop distribution to attempt to isolate the offending operations into a separate loop
48+
; CHECK-NEXT: Unsafe indirect dependence.
4849
; CHECK-NEXT: Dependences:
50+
; CHECK-NEXT: IndirectUnsafe:
51+
; CHECK-NEXT: %load = load double, ptr %gep.sel, align 8 ->
52+
; CHECK-NEXT: store double %load, ptr %gep.sel2, align 8
53+
; CHECK-EMPTY:
4954
; CHECK-NEXT: Run-time memory checks:
5055
; CHECK-NEXT: Grouped accesses:
5156
; CHECK-EMPTY:

0 commit comments

Comments
 (0)