diff --git a/llvm/lib/Target/AMDGPU/SIPreEmitPeephole.cpp b/llvm/lib/Target/AMDGPU/SIPreEmitPeephole.cpp --- a/llvm/lib/Target/AMDGPU/SIPreEmitPeephole.cpp +++ b/llvm/lib/Target/AMDGPU/SIPreEmitPeephole.cpp @@ -30,6 +30,7 @@ const SIRegisterInfo *TRI = nullptr; bool optimizeVccBranch(MachineInstr &MI) const; + bool optimizeSetGPR(MachineInstr &First, MachineInstr &MI) const; public: static char ID; @@ -143,6 +144,54 @@ return true; } +bool SIPreEmitPeephole::optimizeSetGPR(MachineInstr &First, + MachineInstr &MI) const { + MachineBasicBlock &MBB = *MI.getParent(); + const MachineFunction &MF = *MBB.getParent(); + const MachineRegisterInfo &MRI = MF.getRegInfo(); + MachineOperand *Idx = TII->getNamedOperand(MI, AMDGPU::OpName::src0); + Register IdxReg = Idx->isReg() ? Idx->getReg() : Register(); + SmallVector ToRemove; + bool IdxOn = true; + + if (!MI.isIdenticalTo(First)) + return false; + + // Scan back to find an identical S_SET_GPR_IDX_ON + for (MachineBasicBlock::iterator I = std::next(First.getIterator()), + E = MI.getIterator(); I != E; ++I) { + switch (I->getOpcode()) { + case AMDGPU::S_SET_GPR_IDX_MODE: + return false; + case AMDGPU::S_SET_GPR_IDX_OFF: + IdxOn = false; + ToRemove.push_back(&*I); + break; + default: + if (I->modifiesRegister(AMDGPU::M0, TRI)) + return false; + if (IdxReg && I->modifiesRegister(IdxReg, TRI)) + return false; + if (llvm::any_of(I->operands(), + [&MRI, this](const MachineOperand &MO) { + return MO.isReg() && + TRI->isVectorRegister(MRI, MO.getReg()); + })) { + // The only exception allowed here is another indirect V_MOV_B32_e32 + // with the same mode. + if (!IdxOn || I->getOpcode() != AMDGPU::V_MOV_B32_e32 || + !I->hasRegisterImplicitUseOperand(AMDGPU::M0)) + return false; + } + } + } + + MI.eraseFromParent(); + for (MachineInstr *RI : ToRemove) + RI->eraseFromParent(); + return true; +} + bool SIPreEmitPeephole::runOnMachineFunction(MachineFunction &MF) { const GCNSubtarget &ST = MF.getSubtarget(); TII = ST.getInstrInfo(); @@ -150,18 +199,50 @@ bool Changed = false; for (MachineBasicBlock &MBB : MF) { - MachineBasicBlock::iterator MBBI = MBB.getFirstTerminator(); - if (MBBI == MBB.end()) + MachineBasicBlock::iterator MBBE = MBB.getFirstTerminator(); + if (MBBE != MBB.end()) { + MachineInstr &MI = *MBBE; + switch (MI.getOpcode()) { + case AMDGPU::S_CBRANCH_VCCZ: + case AMDGPU::S_CBRANCH_VCCNZ: + Changed |= optimizeVccBranch(MI); + continue; + default: + break; + } + } + + if (!ST.hasVGPRIndexMode()) continue; - MachineInstr &MI = *MBBI; - switch (MI.getOpcode()) { - case AMDGPU::S_CBRANCH_VCCZ: - case AMDGPU::S_CBRANCH_VCCNZ: - Changed |= optimizeVccBranch(MI); - break; - default: - break; + MachineInstr *SetGPRMI = nullptr; + const unsigned Threshold = 20; + unsigned Count = 0; + // Scan the block for two S_SET_GPR_IDX_ON instructions to see if a + // second is not needed. Do expensive checks in the optimizeSetGPR() + // and limit the distance to 20 instructions for compile time purposes. + for (MachineBasicBlock::iterator MBBI = MBB.begin(); MBBI != MBBE; ) { + MachineInstr &MI = *MBBI; + ++MBBI; + + if (Count == Threshold) + SetGPRMI = nullptr; + else + ++Count; + + if (MI.getOpcode() != AMDGPU::S_SET_GPR_IDX_ON) + continue; + + Count = 0; + if (!SetGPRMI) { + SetGPRMI = &MI; + continue; + } + + if (optimizeSetGPR(*SetGPRMI, MI)) + Changed = true; + else + SetGPRMI = &MI; } } diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/extractelement.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/extractelement.ll --- a/llvm/test/CodeGen/AMDGPU/GlobalISel/extractelement.ll +++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/extractelement.ll @@ -428,8 +428,6 @@ ; GPRIDX-NEXT: v_cmp_eq_u32_e32 vcc, s6, v16 ; GPRIDX-NEXT: s_set_gpr_idx_on s7, gpr_idx(SRC0) ; GPRIDX-NEXT: v_mov_b32_e32 v17, v0 -; GPRIDX-NEXT: s_set_gpr_idx_off -; GPRIDX-NEXT: s_set_gpr_idx_on s7, gpr_idx(SRC0) ; GPRIDX-NEXT: v_mov_b32_e32 v18, v1 ; GPRIDX-NEXT: s_set_gpr_idx_off ; GPRIDX-NEXT: s_and_saveexec_b64 vcc, vcc @@ -470,8 +468,6 @@ ; GPRIDX-NEXT: s_lshl_b32 s0, s2, 1 ; GPRIDX-NEXT: s_set_gpr_idx_on s0, gpr_idx(SRC0) ; GPRIDX-NEXT: v_mov_b32_e32 v16, v0 -; GPRIDX-NEXT: s_set_gpr_idx_off -; GPRIDX-NEXT: s_set_gpr_idx_on s0, gpr_idx(SRC0) ; GPRIDX-NEXT: v_mov_b32_e32 v17, v1 ; GPRIDX-NEXT: s_set_gpr_idx_off ; GPRIDX-NEXT: global_store_dwordx2 v[0:1], v[16:17], off @@ -1036,8 +1032,6 @@ ; GPRIDX-NEXT: v_cmp_eq_u32_e32 vcc, s6, v16 ; GPRIDX-NEXT: s_set_gpr_idx_on s7, gpr_idx(SRC0) ; GPRIDX-NEXT: v_mov_b32_e32 v17, v0 -; GPRIDX-NEXT: s_set_gpr_idx_off -; GPRIDX-NEXT: s_set_gpr_idx_on s7, gpr_idx(SRC0) ; GPRIDX-NEXT: v_mov_b32_e32 v18, v1 ; GPRIDX-NEXT: s_set_gpr_idx_off ; GPRIDX-NEXT: s_and_saveexec_b64 vcc, vcc @@ -1164,8 +1158,6 @@ ; GPRIDX-NEXT: v_cmp_eq_u32_e32 vcc, s6, v16 ; GPRIDX-NEXT: s_set_gpr_idx_on s7, gpr_idx(SRC0) ; GPRIDX-NEXT: v_mov_b32_e32 v17, v0 -; GPRIDX-NEXT: s_set_gpr_idx_off -; GPRIDX-NEXT: s_set_gpr_idx_on s7, gpr_idx(SRC0) ; GPRIDX-NEXT: v_mov_b32_e32 v18, v1 ; GPRIDX-NEXT: s_set_gpr_idx_off ; GPRIDX-NEXT: s_and_saveexec_b64 vcc, vcc @@ -1298,8 +1290,6 @@ ; GPRIDX-NEXT: s_lshl_b32 s0, s2, 1 ; GPRIDX-NEXT: s_set_gpr_idx_on s0, gpr_idx(SRC0) ; GPRIDX-NEXT: v_mov_b32_e32 v32, v0 -; GPRIDX-NEXT: s_set_gpr_idx_off -; GPRIDX-NEXT: s_set_gpr_idx_on s0, gpr_idx(SRC0) ; GPRIDX-NEXT: v_mov_b32_e32 v0, v1 ; GPRIDX-NEXT: s_set_gpr_idx_off ; GPRIDX-NEXT: v_readfirstlane_b32 s0, v32 diff --git a/llvm/test/CodeGen/AMDGPU/set-gpr-idx-peephole.mir b/llvm/test/CodeGen/AMDGPU/set-gpr-idx-peephole.mir new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/set-gpr-idx-peephole.mir @@ -0,0 +1,338 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py +# RUN: llc -march=amdgcn -mcpu=gfx900 -run-pass si-pre-emit-peephole -verify-machineinstrs -o - %s | FileCheck -check-prefix=GCN %s + +--- +name: simple +body: | + bb.0: + + ; GCN-LABEL: name: simple + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: salu_in_between +body: | + bb.0: + + ; GCN-LABEL: name: salu_in_between + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: $sgpr0 = S_MOV_B32 $sgpr2 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + $sgpr0 = S_MOV_B32 $sgpr2 + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: valu_write_in_between +body: | + bb.0: + + ; GCN-LABEL: name: valu_write_in_between + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + ; GCN: $vgpr20 = V_MOV_B32_e32 1, implicit $exec + ; GCN: S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + $vgpr20 = V_MOV_B32_e32 1, implicit $exec + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: valu_read_in_between +body: | + bb.0: + + ; GCN-LABEL: name: valu_read_in_between + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + ; GCN: V_NOP_e32 implicit $exec, implicit $vgpr0 + ; GCN: S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + V_NOP_e32 implicit $exec, implicit $vgpr0 + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: changed_index +body: | + bb.0: + + ; GCN-LABEL: name: changed_index + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + ; GCN: $sgpr2 = S_MOV_B32 1 + ; GCN: S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + $sgpr2 = S_MOV_B32 1 + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: implicitly_changed_index +body: | + bb.0: + + ; GCN-LABEL: name: implicitly_changed_index + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + ; GCN: S_NOP 0, implicit-def $sgpr2 + ; GCN: S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_NOP 0, implicit-def $sgpr2 + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: changed_m0 +body: | + bb.0: + + ; GCN-LABEL: name: changed_m0 + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + ; GCN: $m0 = S_MOV_B32 1 + ; GCN: S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + $m0 = S_MOV_B32 1 + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: implicitly_changed_m0 +body: | + bb.0: + + ; GCN-LABEL: name: implicitly_changed_m0 + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + ; GCN: S_NOP 0, implicit-def $m0 + ; GCN: S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_NOP 0, implicit-def $m0 + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: same_imm_index +body: | + bb.0: + + ; GCN-LABEL: name: same_imm_index + ; GCN: S_SET_GPR_IDX_ON 1, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON 1, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON 1, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +name: different_imm_index +body: | + bb.0: + + S_SET_GPR_IDX_ON 1, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON 2, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: different_gpr_index +body: | + bb.0: + + ; GCN-LABEL: name: different_gpr_index + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + ; GCN: S_SET_GPR_IDX_ON killed $sgpr1, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON killed $sgpr1, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: different_gpr_index_then_same_index +body: | + bb.0: + + ; GCN-LABEL: name: different_gpr_index_then_same_index + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + ; GCN: S_SET_GPR_IDX_ON $sgpr1, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + ; GCN: S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr1, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: use_m0_with_idx_off +body: | + bb.0: + + ; GCN-LABEL: name: use_m0_with_idx_off + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: S_SET_GPR_IDX_OFF + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + S_SET_GPR_IDX_OFF + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: three_in_a_row +body: | + bb.0: + + ; GCN-LABEL: name: three_in_a_row + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: $vgpr17 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: $vgpr18 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr17 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr18 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: different_gpr_index_then_two_same_indexes +body: | + bb.0: + + ; GCN-LABEL: name: different_gpr_index_then_two_same_indexes + ; GCN: S_SET_GPR_IDX_ON $sgpr1, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr1, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON killed $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +... + +--- +name: two_same_indexes_then_different +body: | + bb.0: + + ; GCN-LABEL: name: two_same_indexes_then_different + ; GCN: S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + ; GCN: S_SET_GPR_IDX_ON killed $sgpr1, 1, implicit-def $m0, implicit undef $m0 + ; GCN: $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + ; GCN: S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON $sgpr2, 1, implicit-def $m0, implicit undef $m0 + $vgpr16 = V_MOV_B32_e32 undef $vgpr1, implicit $exec, implicit $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF + S_SET_GPR_IDX_ON killed $sgpr1, 1, implicit-def $m0, implicit undef $m0 + $vgpr15 = V_MOV_B32_e32 undef $vgpr0, implicit $exec, implicit killed $vgpr0_vgpr1_vgpr2_vgpr3_vgpr4_vgpr5_vgpr6_vgpr7_vgpr8_vgpr9_vgpr10_vgpr11_vgpr12_vgpr13_vgpr14_vgpr15, implicit $m0 + S_SET_GPR_IDX_OFF +...