diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp @@ -3417,7 +3417,11 @@ case TargetOpcode::G_ZEXT: case TargetOpcode::G_ANYEXT: case TargetOpcode::G_SEXT_INREG: - if (selectImpl(I, *CoverageInfo)) + // This is a workaround. For extension from type i1, `selectImpl()` uses + // patterns from TD file and generates an illegal VGPR to SGPR COPY as type + // i1 can only be hold in a SGPR class. + if (MRI->getType(I.getOperand(1).getReg()) != LLT::scalar(1) && + selectImpl(I, *CoverageInfo)) return true; return selectG_SZA_EXT(I); case TargetOpcode::G_BRCOND: diff --git a/llvm/lib/Target/AMDGPU/SIInstructions.td b/llvm/lib/Target/AMDGPU/SIInstructions.td --- a/llvm/lib/Target/AMDGPU/SIInstructions.td +++ b/llvm/lib/Target/AMDGPU/SIInstructions.td @@ -2020,13 +2020,13 @@ def : GCNPat < (i32 (sext i1:$src0)), (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), - /*src1mod*/(i32 0), /*src1*/(i32 -1), $src0) + /*src1mod*/(i32 0), /*src1*/(i32 -1), i1:$src0) >; class Ext32Pat : GCNPat < (i32 (ext i1:$src0)), (V_CNDMASK_B32_e64 /*src0mod*/(i32 0), /*src0*/(i32 0), - /*src1mod*/(i32 0), /*src1*/(i32 1), $src0) + /*src1mod*/(i32 0), /*src1*/(i32 1), i1:$src0) >; def : Ext32Pat ;