Skip to content

Commit 30124cf

Browse files
committed
[AMDGPU] Fix register class constraints for si-fold-operands pass
Fixes #130020 This fixes an issue where the si-fold-operands pass would incorrectly fold immediate values into COPY instructions targeting av_32 registers, which is illegal. The pass now properly checks register class constraints before attempting to fold the immediates.
1 parent 955c02d commit 30124cf

File tree

2 files changed

+51
-49
lines changed

2 files changed

+51
-49
lines changed

llvm/lib/Target/AMDGPU/SIFoldOperands.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,11 @@ void SIFoldOperandsImpl::foldOperand(
10471047
if (MovOp == AMDGPU::COPY)
10481048
return;
10491049

1050+
// Check if the destination register of the MOV operation belongs
1051+
// to a vector superclass. Folding would be illegal.
1052+
if (TRI->isVectorSuperClass(DestRC))
1053+
return;
1054+
10501055
MachineInstr::mop_iterator ImpOpI = UseMI->implicit_operands().begin();
10511056
MachineInstr::mop_iterator ImpOpE = UseMI->implicit_operands().end();
10521057
while (ImpOpI != ImpOpE) {

llvm/test/CodeGen/AMDGPU/fold-imm-copy.mir

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -185,52 +185,49 @@ body: |
185185
186186
...
187187

188-
# FIXME: Register class restrictions of av register not respected,
189-
# issue 130020
190-
191-
# ---
192-
# name: s_mov_b32_inlineimm_copy_s_to_av_32
193-
# tracksRegLiveness: true
194-
# body: |
195-
# bb.0:
196-
# %0:sreg_32 = S_MOV_B32 32
197-
# %1:av_32 = COPY %0
198-
# $agpr0 = COPY %1
199-
# S_ENDPGM 0
200-
201-
# ...
202-
203-
# ---
204-
# name: v_mov_b32_inlineimm_copy_v_to_av_32
205-
# tracksRegLiveness: true
206-
# body: |
207-
# bb.0:
208-
# %0:vgpr_32 = V_MOV_B32_e32 32, implicit $exec
209-
# %1:av_32 = COPY %0
210-
# $agpr0 = COPY %1
211-
# S_ENDPGM 0
212-
# ...
213-
214-
# ---
215-
# name: s_mov_b32_imm_literal_copy_s_to_av_32
216-
# tracksRegLiveness: true
217-
# body: |
218-
# bb.0:
219-
# %0:sreg_32 = S_MOV_B32 999
220-
# %1:av_32 = COPY %0
221-
# $agpr0 = COPY %1
222-
# S_ENDPGM 0
223-
224-
# ...
225-
226-
# ---
227-
# name: v_mov_b32_imm_literal_copy_v_to_av_32
228-
# tracksRegLiveness: true
229-
# body: |
230-
# bb.0:
231-
# %0:vgpr_32 = V_MOV_B32_e32 999, implicit $exec
232-
# %1:av_32 = COPY %0
233-
# $agpr0 = COPY %1
234-
# S_ENDPGM 0
235-
236-
# ...
188+
---
189+
name: s_mov_b32_inlineimm_copy_s_to_av_32
190+
tracksRegLiveness: true
191+
body: |
192+
bb.0:
193+
%0:sreg_32 = S_MOV_B32 32
194+
%1:av_32 = COPY %0
195+
$agpr0 = COPY %1
196+
S_ENDPGM 0
197+
198+
...
199+
200+
---
201+
name: v_mov_b32_inlineimm_copy_v_to_av_32
202+
tracksRegLiveness: true
203+
body: |
204+
bb.0:
205+
%0:vgpr_32 = V_MOV_B32_e32 32, implicit $exec
206+
%1:av_32 = COPY %0
207+
$agpr0 = COPY %1
208+
S_ENDPGM 0
209+
...
210+
211+
---
212+
name: s_mov_b32_imm_literal_copy_s_to_av_32
213+
tracksRegLiveness: true
214+
body: |
215+
bb.0:
216+
%0:sreg_32 = S_MOV_B32 999
217+
%1:av_32 = COPY %0
218+
$agpr0 = COPY %1
219+
S_ENDPGM 0
220+
221+
...
222+
223+
---
224+
name: v_mov_b32_imm_literal_copy_v_to_av_32
225+
tracksRegLiveness: true
226+
body: |
227+
bb.0:
228+
%0:vgpr_32 = V_MOV_B32_e32 999, implicit $exec
229+
%1:av_32 = COPY %0
230+
$agpr0 = COPY %1
231+
S_ENDPGM 0
232+
233+
...

0 commit comments

Comments
 (0)