[llvm] e636434 - [BasicAA][LAA] Don't use same-block phis in cross iteration mode (#116802)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 27 00:38:55 PST 2024
Author: Nikita Popov
Date: 2024-11-27T09:38:51+01:00
New Revision: e636434bdf74cf40071b776ef05aafbf161ce4cd
URL: https://github.com/llvm/llvm-project/commit/e636434bdf74cf40071b776ef05aafbf161ce4cd
DIFF: https://github.com/llvm/llvm-project/commit/e636434bdf74cf40071b776ef05aafbf161ce4cd.diff
LOG: [BasicAA][LAA] Don't use same-block phis in cross iteration mode (#116802)
In 4de3184f07fd8c548125d315dd306d4afa7c9698 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.)
Added:
Modified:
llvm/lib/Analysis/BasicAliasAnalysis.cpp
llvm/test/Analysis/LoopAccessAnalysis/select-dependence.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 178ad863eb06a6..381fb7bbdb5171 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1449,9 +1449,10 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize,
return AliasResult::NoAlias;
// If the values are PHIs in the same block, we can do a more precise
// as well as efficient check: just check for aliases between the values
- // on corresponding edges.
+ // on corresponding edges. Don't do this if we are analyzing across
+ // iterations, as we may pick a
diff erent phi entry in
diff erent iterations.
if (const PHINode *PN2 = dyn_cast<PHINode>(V2))
- if (PN2->getParent() == PN->getParent()) {
+ if (PN2->getParent() == PN->getParent() && !AAQI.MayBeCrossIteration) {
std::optional<AliasResult> Alias;
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
AliasResult ThisAlias = AAQI.AAR.alias(
diff --git a/llvm/test/Analysis/LoopAccessAnalysis/select-dependence.ll b/llvm/test/Analysis/LoopAccessAnalysis/select-dependence.ll
index 7d8a25f022e7d0..5b01efd821c474 100644
--- a/llvm/test/Analysis/LoopAccessAnalysis/select-dependence.ll
+++ b/llvm/test/Analysis/LoopAccessAnalysis/select-dependence.ll
@@ -44,8 +44,13 @@ exit:
define void @test_phi(ptr noalias %x, ptr noalias %y, ptr noalias %z) {
; CHECK-LABEL: 'test_phi'
; CHECK-NEXT: loop:
-; CHECK-NEXT: Memory dependences are safe
+; 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
+; CHECK-NEXT: Unsafe indirect dependence.
; CHECK-NEXT: Dependences:
+; CHECK-NEXT: IndirectUnsafe:
+; CHECK-NEXT: %load = load double, ptr %gep.sel, align 8 ->
+; CHECK-NEXT: store double %load, ptr %gep.sel2, align 8
+; CHECK-EMPTY:
; CHECK-NEXT: Run-time memory checks:
; CHECK-NEXT: Grouped accesses:
; CHECK-EMPTY:
More information about the llvm-commits
mailing list