Skip to content

Commit 006858c

Browse files
authored
[AMDGPU] Prevent folding of FI with scale_offset on gfx1250 (#149894)
SS forms of SCRATCH_LOAD_DWORD do not support SCALE_OFFSET, so if this bit is used SCRATCH_LOAD_DWORD_SADDR cannot be formed. This generally shall not happen because FI is not supposed to be scaled, but add this as a precaution.
1 parent a0b854d commit 006858c

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

llvm/lib/Target/AMDGPU/SIFoldOperands.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,18 +1209,24 @@ void SIFoldOperandsImpl::foldOperand(
12091209
return;
12101210
}
12111211

1212-
// A frame index will resolve to a positive constant, so it should always be
1213-
// safe to fold the addressing mode, even pre-GFX9.
1214-
UseMI->getOperand(UseOpIdx).ChangeToFrameIndex(OpToFold.getFI());
1215-
12161212
const unsigned Opc = UseMI->getOpcode();
12171213
if (TII->isFLATScratch(*UseMI) &&
12181214
AMDGPU::hasNamedOperand(Opc, AMDGPU::OpName::vaddr) &&
12191215
!AMDGPU::hasNamedOperand(Opc, AMDGPU::OpName::saddr)) {
12201216
unsigned NewOpc = AMDGPU::getFlatScratchInstSSfromSV(Opc);
1217+
unsigned CPol =
1218+
TII->getNamedOperand(*UseMI, AMDGPU::OpName::cpol)->getImm();
1219+
if ((CPol & AMDGPU::CPol::SCAL) &&
1220+
!AMDGPU::supportsScaleOffset(*TII, NewOpc))
1221+
return;
1222+
12211223
UseMI->setDesc(TII->get(NewOpc));
12221224
}
12231225

1226+
// A frame index will resolve to a positive constant, so it should always be
1227+
// safe to fold the addressing mode, even pre-GFX9.
1228+
UseMI->getOperand(UseOpIdx).ChangeToFrameIndex(OpToFold.getFI());
1229+
12241230
return;
12251231
}
12261232

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2
2+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1250 -start-before=si-fold-operands -stop-after=prologepilog -o - %s | FileCheck -check-prefix=GCN %s
3+
4+
---
5+
name: test_fold_fi_scratch_load_vgpr
6+
tracksRegLiveness: true
7+
machineFunctionInfo:
8+
scratchRSrcReg: $sgpr0_sgpr1_sgpr2_sgpr3
9+
stackPtrOffsetReg: $sgpr32
10+
stack:
11+
- { id: 0, name: '', type: spill-slot, offset: 0, size: 4, alignment: 4 }
12+
body: |
13+
bb.0.entry:
14+
; GCN-LABEL: name: test_fold_fi_scratch_load_vgpr
15+
; GCN: renamable $vgpr0 = SCRATCH_LOAD_DWORD_SADDR $sgpr32, 4, 0, implicit $exec, implicit $flat_scr :: (load (s32) from %stack.0, addrspace 5)
16+
; GCN-NEXT: S_ENDPGM 0, implicit killed renamable $vgpr0
17+
%0:vgpr_32 = V_MOV_B32_e32 %stack.0, implicit $exec
18+
%1:vgpr_32 = SCRATCH_LOAD_DWORD %0:vgpr_32, 4, 0, implicit $exec, implicit $flat_scr :: (load 4 from %stack.0, addrspace 5)
19+
S_ENDPGM 0, implicit %1
20+
21+
...
22+
23+
# SS form of the SCRATCH_LOAD_DWORD does not support offset scaling
24+
25+
---
26+
name: test_no_fold_fi_scratch_load_vgpr_scale_offset
27+
tracksRegLiveness: true
28+
machineFunctionInfo:
29+
scratchRSrcReg: $sgpr0_sgpr1_sgpr2_sgpr3
30+
stackPtrOffsetReg: $sgpr32
31+
stack:
32+
- { id: 0, name: '', type: spill-slot, offset: 0, size: 4, alignment: 4 }
33+
body: |
34+
bb.0.entry:
35+
; GCN-LABEL: name: test_no_fold_fi_scratch_load_vgpr_scale_offset
36+
; GCN: renamable $vgpr0 = V_MOV_B32_e32 $sgpr32, implicit $exec
37+
; GCN-NEXT: renamable $vgpr0 = SCRATCH_LOAD_DWORD killed renamable $vgpr0, 4, 2048, implicit $exec, implicit $flat_scr :: (load (s32) from %stack.0, addrspace 5)
38+
; GCN-NEXT: S_ENDPGM 0, implicit killed renamable $vgpr0
39+
%0:vgpr_32 = V_MOV_B32_e32 %stack.0, implicit $exec
40+
%1:vgpr_32 = SCRATCH_LOAD_DWORD %0:vgpr_32, 4, 2048, implicit $exec, implicit $flat_scr :: (load 4 from %stack.0, addrspace 5)
41+
S_ENDPGM 0, implicit %1
42+
43+
...

0 commit comments

Comments
 (0)