[llvm] [PHIElimination] Declare MachineLoopInfo dependency for Legacy PM (PR #169693)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 26 09:38:00 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Prasoon Mishra (PrasoonMishra)
<details>
<summary>Changes</summary>
PHIElimination uses MachineLoopInfo for loop-exiting critical edge splitting but wasn't declaring this dependency via addUsedIfAvailable() in getAnalysisUsage(). Without this declaration, the pass manager does not make MachineLoopInfo accessible to PHIElimination, causing getAnalysisIfAvailable() to return nullptr.
Without MachineLoopInfo, the loop-exiting edge optimization doesn't fire, resulting in fewer critical edge splits and potentially suboptimal code placement.
This patch adds:
- AU.addUsedIfAvailable<MachineLoopInfoWrapperPass>() to declare the optional dependency
- A test that verifies the optimization fires when MLI is accessible
---
Full diff: https://github.com/llvm/llvm-project/pull/169693.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/PHIElimination.cpp (+1)
- (added) llvm/test/CodeGen/AMDGPU/phi-elim-mli-available.mir (+44)
``````````diff
diff --git a/llvm/lib/CodeGen/PHIElimination.cpp b/llvm/lib/CodeGen/PHIElimination.cpp
index 34a9d5d0e401f..74e46121e65c7 100644
--- a/llvm/lib/CodeGen/PHIElimination.cpp
+++ b/llvm/lib/CodeGen/PHIElimination.cpp
@@ -201,6 +201,7 @@ INITIALIZE_PASS_END(PHIElimination, DEBUG_TYPE,
void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addUsedIfAvailable<LiveVariablesWrapperPass>();
+ AU.addUsedIfAvailable<MachineLoopInfoWrapperPass>();
AU.addPreserved<LiveVariablesWrapperPass>();
AU.addPreserved<SlotIndexesWrapperPass>();
AU.addPreserved<LiveIntervalsWrapperPass>();
diff --git a/llvm/test/CodeGen/AMDGPU/phi-elim-mli-available.mir b/llvm/test/CodeGen/AMDGPU/phi-elim-mli-available.mir
new file mode 100644
index 0000000000000..90315cae9d34c
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/phi-elim-mli-available.mir
@@ -0,0 +1,44 @@
+# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -run-pass=machine-loops,livevars,phi-node-elimination -no-phi-elim-live-out-early-exit -stats -filetype=null %s 2>&1 | FileCheck %s
+# REQUIRES: asserts
+
+# Test that PHIElimination accesses MachineLoopInfo if available for
+# loop-aware edge splitting. The -no-phi-elim-live-out-early-exit flag
+# ensures we reach the loop exiting edge optimization code path.
+#
+# CHECK: 2 phi-node-elimination - Number of critical edges split
+
+---
+name: test_loop_exit_edge_split
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $vgpr0, $sgpr0
+ %0:vgpr_32 = COPY $vgpr0
+ %1:sgpr_32 = COPY $sgpr0
+ %2:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
+ S_BRANCH %bb.1
+
+ bb.1:
+ ; Loop header with PHI (multiple predecessors: bb.0, bb.2)
+ %3:vgpr_32 = PHI %2, %bb.0, %4, %bb.2
+
+ %10:sreg_64_xexec = V_CMP_LT_I32_e64 %3, %1, implicit $exec
+ $vcc = COPY %10
+ S_CBRANCH_VCCNZ %bb.3, implicit $vcc
+ S_BRANCH %bb.2
+
+ bb.2:
+ ; Loop body with two successors
+ %4:vgpr_32 = V_ADD_U32_e64 %3, %0, 0, implicit $exec
+
+ %11:sreg_64_xexec = V_CMP_EQ_U32_e64 %4, %1, implicit $exec
+ $vcc = COPY %11
+ S_CBRANCH_VCCNZ %bb.3, implicit $vcc
+ S_BRANCH %bb.1
+
+ bb.3:
+ ; Exit - PHI with values from both bb.1 and bb.2
+ %5:vgpr_32 = PHI %3, %bb.1, %4, %bb.2
+ $vgpr0 = COPY %5
+ SI_RETURN implicit $vgpr0
+...
``````````
</details>
https://github.com/llvm/llvm-project/pull/169693
More information about the llvm-commits
mailing list