[llvm] [AMDGPU][GlobalISel] Expand SGPR S1 exts into G_SELECT (PR #68858)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 12 01:40:16 PDT 2023
================
@@ -2556,16 +2556,62 @@ void AMDGPURegisterBankInfo::applyMappingImpl(
case AMDGPU::G_SEXT:
case AMDGPU::G_ZEXT:
case AMDGPU::G_ANYEXT: {
+ Register DstReg = MI.getOperand(0).getReg();
Register SrcReg = MI.getOperand(1).getReg();
LLT SrcTy = MRI.getType(SrcReg);
const bool Signed = Opc == AMDGPU::G_SEXT;
+ const LLT S16 = LLT::scalar(16);
+ const LLT S32 = LLT::scalar(32);
+ const LLT S64 = LLT::scalar(64);
+
assert(OpdMapper.getVRegs(1).empty());
const RegisterBank *SrcBank =
OpdMapper.getInstrMapping().getOperandMapping(1).BreakDown[0].RegBank;
- Register DstReg = MI.getOperand(0).getReg();
+ LLT SelType = MRI.getType(MI.getOperand(0).getReg());
+
+ // Extending SGPR S1 to S16/32/64.
+ if (SrcBank == &AMDGPU::SGPRRegBank &&
+ MRI.getType(SrcReg) == LLT::scalar(1) &&
+ (SelType == S32 || SelType == S16 || SelType == S64)) {
+
+ Register False = B.buildConstant(S32, 0).getReg(0);
+ MRI.setRegBank(False, AMDGPU::SGPRRegBank);
+
+ Register True = Signed ? B.buildConstant(S32, -1).getReg(0)
+ : B.buildConstant(S32, 1).getReg(0);
+ MRI.setRegBank(True, AMDGPU::SGPRRegBank);
+
+ B.setInstrAndDebugLoc(MI);
+ Register NewReg = MRI.createGenericVirtualRegister(S32);
+ B.buildInstr(AMDGPU::G_ANYEXT, {NewReg}, {MI.getOperand(1).getReg()});
+ MRI.setRegBank(NewReg, AMDGPU::SGPRRegBank);
+
+ if (SelType == S32) {
+ B.buildSelect(DstReg, NewReg, True, False);
+ } else if (SelType == S16) {
+ Register TmpReg = B.buildSelect(S32, NewReg, True, False).getReg(0);
----------------
jayfoad wrote:
Would it be simpler to build an s16 G_SELECT? I think they are legal even for SGPRs, aren't they?
https://github.com/llvm/llvm-project/pull/68858
More information about the llvm-commits
mailing list