Skip to content

Commit 4733be6

Browse files
committed
AMDGPU/GlobalISel: Implement select for G_INSERT
Reviewers: arsenm Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, rovka, kristof.beyls, dstuttard, tpr, t-tye, llvm-commits Differential Revision: https://reviews.llvm.org/D53116 llvm-svn: 344310
1 parent 0a5fcef commit 4733be6

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,34 @@ bool AMDGPUInstructionSelector::selectG_IMPLICIT_DEF(MachineInstr &I) const {
178178
return true;
179179
}
180180

181+
bool AMDGPUInstructionSelector::selectG_INSERT(MachineInstr &I) const {
182+
MachineBasicBlock *BB = I.getParent();
183+
MachineFunction *MF = BB->getParent();
184+
MachineRegisterInfo &MRI = MF->getRegInfo();
185+
unsigned SubReg = TRI.getSubRegFromChannel(I.getOperand(3).getImm() / 32);
186+
DebugLoc DL = I.getDebugLoc();
187+
MachineInstr *Ins = BuildMI(*BB, &I, DL, TII.get(TargetOpcode::INSERT_SUBREG))
188+
.addDef(I.getOperand(0).getReg())
189+
.addReg(I.getOperand(1).getReg())
190+
.addReg(I.getOperand(2).getReg())
191+
.addImm(SubReg);
192+
193+
for (const MachineOperand &MO : Ins->operands()) {
194+
if (!MO.isReg())
195+
continue;
196+
if (TargetRegisterInfo::isPhysicalRegister(MO.getReg()))
197+
continue;
198+
199+
const TargetRegisterClass *RC =
200+
TRI.getConstrainedRegClassForOperand(MO, MRI);
201+
if (!RC)
202+
continue;
203+
RBI.constrainGenericRegister(MO.getReg(), *RC, MRI);
204+
}
205+
I.eraseFromParent();
206+
return true;
207+
}
208+
181209
bool AMDGPUInstructionSelector::selectG_INTRINSIC(MachineInstr &I,
182210
CodeGenCoverage &CoverageInfo) const {
183211
unsigned IntrinsicID = I.getOperand(1).getIntrinsicID();
@@ -640,6 +668,8 @@ bool AMDGPUInstructionSelector::select(MachineInstr &I,
640668
return selectG_GEP(I);
641669
case TargetOpcode::G_IMPLICIT_DEF:
642670
return selectG_IMPLICIT_DEF(I);
671+
case TargetOpcode::G_INSERT:
672+
return selectG_INSERT(I);
643673
case TargetOpcode::G_INTRINSIC:
644674
return selectG_INTRINSIC(I, CoverageInfo);
645675
case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:

llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class AMDGPUInstructionSelector : public InstructionSelector {
6767
bool selectG_ADD(MachineInstr &I) const;
6868
bool selectG_GEP(MachineInstr &I) const;
6969
bool selectG_IMPLICIT_DEF(MachineInstr &I) const;
70+
bool selectG_INSERT(MachineInstr &I) const;
7071
bool selectG_INTRINSIC(MachineInstr &I, CodeGenCoverage &CoverageInfo) const;
7172
bool selectG_INTRINSIC_W_SIDE_EFFECTS(MachineInstr &I,
7273
CodeGenCoverage &CoverageInfo) const;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# RUN: llc -march=amdgcn -run-pass=instruction-select -verify-machineinstrs -global-isel %s -o - | FileCheck %s
2+
---
3+
4+
name: insert512
5+
legalized: true
6+
regBankSelected: true
7+
8+
# CHECK-LABEL: insert512
9+
# CHECK: [[BASE:%[0-9]+]]:sreg_512 = IMPLICIT_DEF
10+
# CHECK: [[VAL:%[0-9]+]]:sreg_32_xm0 = IMPLICIT_DEF
11+
# CHECK: [[BASE0:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE]], [[VAL]], %subreg.sub0
12+
# CHECK: [[BASE1:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE0]], [[VAL]], %subreg.sub1
13+
# CHECK: [[BASE2:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE1]], [[VAL]], %subreg.sub2
14+
# CHECK: [[BASE3:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE2]], [[VAL]], %subreg.sub3
15+
# CHECK: [[BASE4:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE3]], [[VAL]], %subreg.sub4
16+
# CHECK: [[BASE5:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE4]], [[VAL]], %subreg.sub5
17+
# CHECK: [[BASE6:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE5]], [[VAL]], %subreg.sub6
18+
# CHECK: [[BASE7:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE6]], [[VAL]], %subreg.sub7
19+
# CHECK: [[BASE8:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE7]], [[VAL]], %subreg.sub8
20+
# CHECK: [[BASE9:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE8]], [[VAL]], %subreg.sub9
21+
# CHECK: [[BASE10:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE9]], [[VAL]], %subreg.sub10
22+
# CHECK: [[BASE11:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE10]], [[VAL]], %subreg.sub11
23+
# CHECK: [[BASE12:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE11]], [[VAL]], %subreg.sub12
24+
# CHECK: [[BASE13:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE12]], [[VAL]], %subreg.sub13
25+
# CHECK: [[BASE14:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE13]], [[VAL]], %subreg.sub14
26+
# CHECK: [[BASE15:%[0-9]+]]:sreg_512 = INSERT_SUBREG [[BASE14]], [[VAL]], %subreg.sub15
27+
28+
body: |
29+
bb.0:
30+
%0:sgpr(s512) = G_IMPLICIT_DEF
31+
%1:sgpr(s32) = G_IMPLICIT_DEF
32+
%2:sgpr(s512) = G_INSERT %0:sgpr, %1:sgpr(s32), 0
33+
%3:sgpr(s512) = G_INSERT %2:sgpr, %1:sgpr(s32), 32
34+
%4:sgpr(s512) = G_INSERT %3:sgpr, %1:sgpr(s32), 64
35+
%5:sgpr(s512) = G_INSERT %4:sgpr, %1:sgpr(s32), 96
36+
%6:sgpr(s512) = G_INSERT %5:sgpr, %1:sgpr(s32), 128
37+
%7:sgpr(s512) = G_INSERT %6:sgpr, %1:sgpr(s32), 160
38+
%8:sgpr(s512) = G_INSERT %7:sgpr, %1:sgpr(s32), 192
39+
%9:sgpr(s512) = G_INSERT %8:sgpr, %1:sgpr(s32), 224
40+
%10:sgpr(s512) = G_INSERT %9:sgpr, %1:sgpr(s32), 256
41+
%11:sgpr(s512) = G_INSERT %10:sgpr, %1:sgpr(s32), 288
42+
%12:sgpr(s512) = G_INSERT %11:sgpr, %1:sgpr(s32), 320
43+
%13:sgpr(s512) = G_INSERT %12:sgpr, %1:sgpr(s32), 352
44+
%14:sgpr(s512) = G_INSERT %13:sgpr, %1:sgpr(s32), 384
45+
%15:sgpr(s512) = G_INSERT %14:sgpr, %1:sgpr(s32), 416
46+
%16:sgpr(s512) = G_INSERT %15:sgpr, %1:sgpr(s32), 448
47+
%17:sgpr(s512) = G_INSERT %16:sgpr, %1:sgpr(s32), 480
48+
$sgpr0_sgpr1_sgpr2_sgpr3_sgpr4_sgpr5_sgpr6_sgpr7_sgpr8_sgpr9_sgpr10_sgpr11_sgpr12_sgpr13_sgpr14_sgpr15 = COPY %17:sgpr(s512)
49+
SI_RETURN_TO_EPILOG $sgpr0_sgpr1_sgpr2_sgpr3_sgpr4_sgpr5_sgpr6_sgpr7_sgpr8_sgpr9_sgpr10_sgpr11_sgpr12_sgpr13_sgpr14_sgpr15

0 commit comments

Comments
 (0)