-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[AMDGPU][True16][CodeGen] S_PACK_XX_B32_B16 lowering for true16 mode #162389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9115,6 +9115,63 @@ void SIInstrInfo::movePackToVALU(SIInstrWorklist &Worklist, | |
MachineOperand &Src1 = Inst.getOperand(2); | ||
const DebugLoc &DL = Inst.getDebugLoc(); | ||
|
||
if (ST.useRealTrue16Insts()) { | ||
Register SrcReg0 = Src0.getReg(); | ||
Register SrcReg1 = Src1.getReg(); | ||
|
||
if (!RI.isVGPR(MRI, SrcReg0)) { | ||
rampitec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SrcReg0 = MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass); | ||
BuildMI(*MBB, Inst, DL, get(AMDGPU::V_MOV_B32_e32), SrcReg0).add(Src0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use copy, may need a separate path if there are non-register inputs |
||
} | ||
if (!RI.isVGPR(MRI, SrcReg1)) { | ||
SrcReg1 = MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass); | ||
BuildMI(*MBB, Inst, DL, get(AMDGPU::V_MOV_B32_e32), SrcReg1).add(Src1); | ||
} | ||
bool isSrc0Reg16 = MRI.constrainRegClass(SrcReg0, &AMDGPU::VGPR_16RegClass); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. VGPR_16 is not a subclass of VGPR_32, how could you constrain it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not trying to constrain but just checking if it's vgpr_16 or not. Maybe I can check the regclass directly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's cleaner, or check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using reg bitwidth, it usually works out cleanest to try the various register class matching functions |
||
bool isSrc1Reg16 = MRI.constrainRegClass(SrcReg1, &AMDGPU::VGPR_16RegClass); | ||
|
||
auto NewMI = BuildMI(*MBB, Inst, DL, get(AMDGPU::REG_SEQUENCE), ResultReg); | ||
switch (Inst.getOpcode()) { | ||
case AMDGPU::S_PACK_LL_B32_B16: { | ||
NewMI | ||
.addReg(SrcReg0, 0, | ||
isSrc0Reg16 ? AMDGPU::NoSubRegister : AMDGPU::lo16) | ||
.addImm(AMDGPU::lo16) | ||
.addReg(SrcReg1, 0, | ||
isSrc1Reg16 ? AMDGPU::NoSubRegister : AMDGPU::lo16) | ||
.addImm(AMDGPU::hi16); | ||
} break; | ||
case AMDGPU::S_PACK_LH_B32_B16: { | ||
NewMI | ||
.addReg(SrcReg0, 0, | ||
isSrc0Reg16 ? AMDGPU::NoSubRegister : AMDGPU::lo16) | ||
.addImm(AMDGPU::lo16) | ||
.addReg(SrcReg1, 0, AMDGPU::hi16) | ||
.addImm(AMDGPU::hi16); | ||
} break; | ||
case AMDGPU::S_PACK_HL_B32_B16: { | ||
NewMI.addReg(SrcReg0, 0, AMDGPU::hi16) | ||
.addImm(AMDGPU::lo16) | ||
.addReg(SrcReg1, 0, | ||
isSrc1Reg16 ? AMDGPU::NoSubRegister : AMDGPU::lo16) | ||
.addImm(AMDGPU::hi16); | ||
} break; | ||
case AMDGPU::S_PACK_HH_B32_B16: { | ||
NewMI.addReg(SrcReg0, 0, AMDGPU::hi16) | ||
.addImm(AMDGPU::lo16) | ||
.addReg(SrcReg1, 0, AMDGPU::hi16) | ||
.addImm(AMDGPU::hi16); | ||
} break; | ||
default: | ||
llvm_unreachable("unhandled s_pack_* instruction"); | ||
} | ||
|
||
MachineOperand &Dest = Inst.getOperand(0); | ||
MRI.replaceRegWith(Dest.getReg(), ResultReg); | ||
addUsersToMoveToVALUWorklist(ResultReg, MRI, Worklist); | ||
return; | ||
} | ||
|
||
switch (Inst.getOpcode()) { | ||
case AMDGPU::S_PACK_LL_B32_B16: { | ||
Register ImmReg = MRI.createVirtualRegister(&AMDGPU::VGPR_32RegClass); | ||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably should get a new mir test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we already have a test for it here fix-sgpr-copies-f16-true16.mir