Skip to content

Commit 0cd523e

Browse files
[PHIElimination] Declare MachineLoopInfo dependency for Legacy PM (#169693)
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: - MachineLoopInfo as an optional dependency - A test that verifies the optimization fires when MLI is accessible
1 parent ddd770d commit 0cd523e

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

llvm/lib/CodeGen/PHIElimination.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ INITIALIZE_PASS_END(PHIElimination, DEBUG_TYPE,
201201

202202
void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
203203
AU.addUsedIfAvailable<LiveVariablesWrapperPass>();
204+
AU.addUsedIfAvailable<MachineLoopInfoWrapperPass>();
204205
AU.addPreserved<LiveVariablesWrapperPass>();
205206
AU.addPreserved<SlotIndexesWrapperPass>();
206207
AU.addPreserved<LiveIntervalsWrapperPass>();
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
2+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -run-pass=machine-loops,livevars,phi-node-elimination -no-phi-elim-live-out-early-exit -o - %s | FileCheck %s
3+
4+
# Test that PHIElimination accesses MachineLoopInfo if available for
5+
# loop-aware edge splitting. The -no-phi-elim-live-out-early-exit flag
6+
# ensures we reach the loop exiting edge optimization code path.
7+
8+
---
9+
name: test_loop_exit_edge_split
10+
tracksRegLiveness: true
11+
body: |
12+
; CHECK-LABEL: name: test_loop_exit_edge_split
13+
; CHECK: bb.0:
14+
; CHECK-NEXT: successors: %bb.1(0x80000000)
15+
; CHECK-NEXT: liveins: $vgpr0, $sgpr0
16+
; CHECK-NEXT: {{ $}}
17+
; CHECK-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY killed $vgpr0
18+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:sgpr_32 = COPY killed $sgpr0
19+
; CHECK-NEXT: [[V_MOV_B32_e32_:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
20+
; CHECK-NEXT: [[COPY2:%[0-9]+]]:vgpr_32 = COPY killed [[V_MOV_B32_e32_]]
21+
; CHECK-NEXT: S_BRANCH %bb.1
22+
; CHECK-NEXT: {{ $}}
23+
; CHECK-NEXT: bb.1:
24+
; CHECK-NEXT: successors: %bb.4(0x40000000), %bb.2(0x40000000)
25+
; CHECK-NEXT: {{ $}}
26+
; CHECK-NEXT: [[COPY3:%[0-9]+]]:vgpr_32 = COPY killed [[COPY2]]
27+
; CHECK-NEXT: [[V_CMP_LT_I32_e64_:%[0-9]+]]:sreg_64_xexec = V_CMP_LT_I32_e64 [[COPY3]], [[COPY1]], implicit $exec
28+
; CHECK-NEXT: $vcc = COPY killed [[V_CMP_LT_I32_e64_]]
29+
; CHECK-NEXT: S_CBRANCH_VCCZ %bb.2, implicit killed $vcc
30+
; CHECK-NEXT: {{ $}}
31+
; CHECK-NEXT: bb.4:
32+
; CHECK-NEXT: successors: %bb.3(0x80000000)
33+
; CHECK-NEXT: {{ $}}
34+
; CHECK-NEXT: [[COPY4:%[0-9]+]]:vgpr_32 = COPY killed [[COPY3]]
35+
; CHECK-NEXT: S_BRANCH %bb.3
36+
; CHECK-NEXT: {{ $}}
37+
; CHECK-NEXT: bb.2:
38+
; CHECK-NEXT: successors: %bb.5(0x40000000), %bb.1(0x40000000)
39+
; CHECK-NEXT: {{ $}}
40+
; CHECK-NEXT: [[V_ADD_U32_e64_:%[0-9]+]]:vgpr_32 = V_ADD_U32_e64 killed [[COPY3]], [[COPY]], 0, implicit $exec
41+
; CHECK-NEXT: [[V_CMP_EQ_U32_e64_:%[0-9]+]]:sreg_64_xexec = V_CMP_EQ_U32_e64 [[V_ADD_U32_e64_]], [[COPY1]], implicit $exec
42+
; CHECK-NEXT: $vcc = COPY killed [[V_CMP_EQ_U32_e64_]]
43+
; CHECK-NEXT: [[COPY2:%[0-9]+]]:vgpr_32 = COPY [[V_ADD_U32_e64_]]
44+
; CHECK-NEXT: S_CBRANCH_VCCZ %bb.1, implicit killed $vcc
45+
; CHECK-NEXT: {{ $}}
46+
; CHECK-NEXT: bb.5:
47+
; CHECK-NEXT: successors: %bb.3(0x80000000)
48+
; CHECK-NEXT: {{ $}}
49+
; CHECK-NEXT: [[COPY4:%[0-9]+]]:vgpr_32 = COPY killed [[V_ADD_U32_e64_]]
50+
; CHECK-NEXT: {{ $}}
51+
; CHECK-NEXT: bb.3:
52+
; CHECK-NEXT: [[COPY5:%[0-9]+]]:vgpr_32 = COPY killed [[COPY4]]
53+
; CHECK-NEXT: $vgpr0 = COPY killed [[COPY5]]
54+
; CHECK-NEXT: SI_RETURN implicit killed $vgpr0
55+
bb.0:
56+
liveins: $vgpr0, $sgpr0
57+
%0:vgpr_32 = COPY $vgpr0
58+
%1:sgpr_32 = COPY $sgpr0
59+
%2:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
60+
S_BRANCH %bb.1
61+
62+
bb.1:
63+
; Loop header with PHI (multiple predecessors: bb.0, bb.2)
64+
%3:vgpr_32 = PHI %2, %bb.0, %4, %bb.2
65+
66+
%10:sreg_64_xexec = V_CMP_LT_I32_e64 %3, %1, implicit $exec
67+
$vcc = COPY %10
68+
S_CBRANCH_VCCNZ %bb.3, implicit $vcc
69+
S_BRANCH %bb.2
70+
71+
bb.2:
72+
; Loop body with two successors
73+
%4:vgpr_32 = V_ADD_U32_e64 %3, %0, 0, implicit $exec
74+
75+
%11:sreg_64_xexec = V_CMP_EQ_U32_e64 %4, %1, implicit $exec
76+
$vcc = COPY %11
77+
S_CBRANCH_VCCNZ %bb.3, implicit $vcc
78+
S_BRANCH %bb.1
79+
80+
bb.3:
81+
; Exit - PHI with values from both bb.1 and bb.2
82+
%5:vgpr_32 = PHI %3, %bb.1, %4, %bb.2
83+
$vgpr0 = COPY %5
84+
SI_RETURN implicit $vgpr0
85+
...

0 commit comments

Comments
 (0)