Skip to content

Commit e636434

Browse files
authored
[BasicAA][LAA] Don't use same-block phis in cross iteration mode (#116802)
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 phi handling in cross-iteration mode. (I'm not entirely sure whether this is also needed when BasicAA enables cross-iteration mode during internal phi recursion, but I wouldn't be surprised if that's the case.)
1 parent c00e532 commit e636434

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
@@ -1449,9 +1449,10 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize,
14491449
return AliasResult::NoAlias;
14501450
// If the values are PHIs in the same block, we can do a more precise
14511451
// as well as efficient check: just check for aliases between the values
1452-
// on corresponding edges.
1452+
// on corresponding edges. Don't do this if we are analyzing across
1453+
// iterations, as we may pick a different phi entry in different iterations.
14531454
if (const PHINode *PN2 = dyn_cast<PHINode>(V2))
1454-
if (PN2->getParent() == PN->getParent()) {
1455+
if (PN2->getParent() == PN->getParent() && !AAQI.MayBeCrossIteration) {
14551456
std::optional<AliasResult> Alias;
14561457
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
14571458
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)