Skip to content

Commit be382de

Browse files
authored
[AMDGPU] Use correct operand order for shifts (#68299)
In a special case in frame index elimination (when the offset is 0), we generate either a S_LSHR_B32 or a V_LSHRREV_B32 using the same code. However, they don't expect their operands in the same order - S_LSHR_B32 takes the value to be shifted first and then the shift amount, whereas V_LSHRREV_B32 has the operands reversed (hence the REV in its name). Update the code & tests to take this into account. Also remove an outdated comment (this code is definitely reachable now that non-entry functions no longer have a fixed emergency scavenge slot).
1 parent 4ccd57d commit be382de

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -2432,10 +2432,13 @@ bool SIRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator MI,
24322432
if (Offset == 0) {
24332433
unsigned OpCode = IsSALU && !LiveSCC ? AMDGPU::S_LSHR_B32
24342434
: AMDGPU::V_LSHRREV_B32_e64;
2435-
// XXX - This never happens because of emergency scavenging slot at 0?
2436-
auto Shift = BuildMI(*MBB, MI, DL, TII->get(OpCode), ResultReg)
2437-
.addImm(ST.getWavefrontSizeLog2())
2438-
.addReg(FrameReg);
2435+
auto Shift = BuildMI(*MBB, MI, DL, TII->get(OpCode), ResultReg);
2436+
if (OpCode == AMDGPU::V_LSHRREV_B32_e64)
2437+
// For V_LSHRREV, the operands are reversed (the shift count goes
2438+
// first).
2439+
Shift.addImm(ST.getWavefrontSizeLog2()).addReg(FrameReg);
2440+
else
2441+
Shift.addReg(FrameReg).addImm(ST.getWavefrontSizeLog2());
24392442
if (IsSALU && !LiveSCC)
24402443
Shift.getInstr()->getOperand(3).setIsDead(); // Mark SCC as dead.
24412444
if (IsSALU && LiveSCC) {

llvm/test/CodeGen/AMDGPU/frame-index.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ body: |
5353
; GCN-LABEL: name: func_add_constant_to_fi_uniform_i32
5454
; GCN: liveins: $sgpr30_sgpr31
5555
; GCN-NEXT: {{ $}}
56-
; GCN-NEXT: $sgpr0 = S_LSHR_B32 6, $sgpr32, implicit-def dead $scc
56+
; GCN-NEXT: $sgpr0 = S_LSHR_B32 $sgpr32, 6, implicit-def dead $scc
5757
; GCN-NEXT: renamable $sgpr4 = nuw S_ADD_I32 killed $sgpr0, 4, implicit-def dead $scc
5858
; GCN-NEXT: renamable $vgpr0 = COPY killed renamable $sgpr4, implicit $exec
5959
; GCN-NEXT: $m0 = S_MOV_B32 -1
@@ -89,7 +89,7 @@ body: |
8989
; GCN-LABEL: name: func_add_constant_to_fi_uniform_SCC_clobber_i32
9090
; GCN: liveins: $sgpr30_sgpr31
9191
; GCN-NEXT: {{ $}}
92-
; GCN-NEXT: $sgpr0 = S_LSHR_B32 6, $sgpr32, implicit-def dead $scc
92+
; GCN-NEXT: $sgpr0 = S_LSHR_B32 $sgpr32, 6, implicit-def dead $scc
9393
; GCN-NEXT: renamable $sgpr4 = nuw S_ADD_U32 killed $sgpr0, 4, implicit-def $scc
9494
; GCN-NEXT: renamable $sgpr5 = S_ADDC_U32 $sgpr4, 1234567, implicit-def $scc, implicit $scc
9595
; GCN-NEXT: $sgpr0 = S_LSHR_B32 $sgpr32, 6, implicit-def $scc

0 commit comments

Comments
 (0)