Skip to content

Commit 945e943

Browse files
authored
[AMDGPU] Fix subreg check in the SIFixSGPRCopies (#70007)
It checks for the copy of subregs, but it checks destination which may never happen in SSA. It misses the subreg check and happily produces S_MOV_B64 out of a subreg COPY. The affected test should have never been formed in the first place because the pass is running in SSA and copies into a subreg shall never happen.
1 parent aceb34c commit 945e943

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ static bool isSafeToFoldImmIntoCopy(const MachineInstr *Copy,
357357
return false;
358358

359359
// FIXME: Handle copies with sub-regs.
360-
if (Copy->getOperand(0).getSubReg())
360+
if (Copy->getOperand(1).getSubReg())
361361
return false;
362362

363363
switch (MoveImm->getOpcode()) {

llvm/test/CodeGen/AMDGPU/fix-sgpr-copies.mir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,14 @@ body: |
222222
%4:sreg_32 = COPY %3:vgpr_32
223223
%5:sreg_32 = nofpexcept S_FMAC_F32 killed %4:sreg_32, %1:sreg_32, %2:sreg_32, implicit $mode
224224
...
225+
226+
---
227+
# GCN-LABEL: name: moveimm_subreg_input
228+
# GCN: %0:vreg_64 = V_MOV_B64_PSEUDO 0, implicit $exec
229+
# GCN: :vgpr_32 = COPY %0.sub0
230+
name: moveimm_subreg_input
231+
body: |
232+
bb.0:
233+
%0:vreg_64 = V_MOV_B64_PSEUDO 0, implicit $exec
234+
%1:sreg_32 = COPY %0.sub0
235+
...

llvm/test/CodeGen/AMDGPU/phi-vgpr-input-moveimm.mir

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ body: |
3434

3535
---
3636
# GCN-LABEL: name: phi_moveimm_subreg_input
37-
# GCN-NOT: %{{[0-9]+}}:sreg_64 = PHI %{{[0-9]+}}, %bb.3, %{{[0-9]+}}, %bb.1
38-
# GCN: %{{[0-9]+}}:vreg_64 = PHI %{{[0-9]+}}, %bb.3, %{{[0-9]+}}, %bb.1
37+
# GCN: %{{[0-9]+}}:sreg_64 = PHI %{{[0-9]+}}, %bb.3, %{{[0-9]+}}, %bb.1
3938
name: phi_moveimm_subreg_input
4039
tracksRegLiveness: true
4140
body: |

0 commit comments

Comments
 (0)