[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 04:34:40 PDT 2023
================
@@ -2556,16 +2556,45 @@ 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(DstReg);
+
+ // Extending SGPR S1 to S16/32/64.
+ if (SrcBank == &AMDGPU::SGPRRegBank &&
+ MRI.getType(SrcReg) == LLT::scalar(1)) {
+ assert(SelType == S32 || SelType == S16 || SelType == S64);
+ B.setInstrAndDebugLoc(MI);
+
+ Register False = B.buildConstant(SelType, 0).getReg(0);
+ MRI.setRegBank(False, AMDGPU::SGPRRegBank);
+
+ Register True = B.buildConstant(SelType, Signed ? -1 : 1).getReg(0);
+ MRI.setRegBank(True, AMDGPU::SGPRRegBank);
+
+ // Extend to S16/S32, but keep it at S32 for S64 SelType.
----------------
jayfoad wrote:
Always extending to S32 would be most consistent with the comment in the legalizer that "Condition should be s32 for scalar, s1 for vector".
https://github.com/llvm/llvm-project/pull/68858
More information about the llvm-commits
mailing list