@@ -817,6 +817,7 @@ bool RISCVRegisterInfo::getRegAllocationHints(
817817 SmallVectorImpl<MCPhysReg> &Hints, const MachineFunction &MF,
818818 const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const {
819819 const MachineRegisterInfo *MRI = &MF.getRegInfo ();
820+ auto &Subtarget = MF.getSubtarget <RISCVSubtarget>();
820821
821822 bool BaseImplRetVal = TargetRegisterInfo::getRegAllocationHints (
822823 VirtReg, Order, Hints, MF, VRM, Matrix);
@@ -844,7 +845,7 @@ bool RISCVRegisterInfo::getRegAllocationHints(
844845
845846 // This is all of the compressible binary instructions. If an instruction
846847 // needs GPRC register class operands \p NeedGPRC will be set to true.
847- auto isCompressible = [](const MachineInstr &MI, bool &NeedGPRC) {
848+ auto isCompressible = [&Subtarget ](const MachineInstr &MI, bool &NeedGPRC) {
848849 NeedGPRC = false ;
849850 switch (MI.getOpcode ()) {
850851 default :
@@ -857,9 +858,16 @@ bool RISCVRegisterInfo::getRegAllocationHints(
857858 case RISCV::SUBW:
858859 NeedGPRC = true ;
859860 return true ;
860- case RISCV::ANDI:
861+ case RISCV::ANDI: {
861862 NeedGPRC = true ;
862- return MI.getOperand (2 ).isImm () && isInt<6 >(MI.getOperand (2 ).getImm ());
863+ if (!MI.getOperand (2 ).isImm ())
864+ return false ;
865+ int64_t Imm = MI.getOperand (2 ).getImm ();
866+ if (isInt<6 >(Imm))
867+ return true ;
868+ // c.zext.b
869+ return Subtarget.hasStdExtZcb () && Imm == 255 ;
870+ }
863871 case RISCV::SRAI:
864872 case RISCV::SRLI:
865873 NeedGPRC = true ;
@@ -870,6 +878,24 @@ bool RISCVRegisterInfo::getRegAllocationHints(
870878 case RISCV::ADDI:
871879 case RISCV::ADDIW:
872880 return MI.getOperand (2 ).isImm () && isInt<6 >(MI.getOperand (2 ).getImm ());
881+ case RISCV::MUL:
882+ case RISCV::SEXT_B:
883+ case RISCV::SEXT_H:
884+ case RISCV::ZEXT_H_RV32:
885+ case RISCV::ZEXT_H_RV64:
886+ // c.mul, c.sext.b, c.sext.h, c.zext.h
887+ NeedGPRC = true ;
888+ return Subtarget.hasStdExtZcb ();
889+ case RISCV::ADD_UW:
890+ // c.zext.w
891+ NeedGPRC = true ;
892+ return Subtarget.hasStdExtZcb () && MI.getOperand (2 ).isReg () &&
893+ MI.getOperand (2 ).getReg () == RISCV::X0;
894+ case RISCV::XORI:
895+ // c.not
896+ NeedGPRC = true ;
897+ return Subtarget.hasStdExtZcb () && MI.getOperand (2 ).isImm () &&
898+ MI.getOperand (2 ).getImm () == -1 ;
873899 }
874900 };
875901
@@ -891,13 +917,15 @@ bool RISCVRegisterInfo::getRegAllocationHints(
891917 bool NeedGPRC;
892918 if (isCompressible (MI, NeedGPRC)) {
893919 if (OpIdx == 0 && MI.getOperand (1 ).isReg ()) {
894- if (!NeedGPRC || isCompressibleOpnd (MI.getOperand (2 )))
920+ if (!NeedGPRC || MI.getNumExplicitOperands () < 3 ||
921+ MI.getOpcode () == RISCV::ADD_UW ||
922+ isCompressibleOpnd (MI.getOperand (2 )))
895923 tryAddHint (MO, MI.getOperand (1 ), NeedGPRC);
896924 if (MI.isCommutable () && MI.getOperand (2 ).isReg () &&
897925 (!NeedGPRC || isCompressibleOpnd (MI.getOperand (1 ))))
898926 tryAddHint (MO, MI.getOperand (2 ), NeedGPRC);
899- } else if (OpIdx == 1 &&
900- (!NeedGPRC || isCompressibleOpnd (MI.getOperand (2 )))) {
927+ } else if (OpIdx == 1 && (!NeedGPRC || MI. getNumExplicitOperands () < 3 ||
928+ isCompressibleOpnd (MI.getOperand (2 )))) {
901929 tryAddHint (MO, MI.getOperand (0 ), NeedGPRC);
902930 } else if (MI.isCommutable () && OpIdx == 2 &&
903931 (!NeedGPRC || isCompressibleOpnd (MI.getOperand (1 )))) {
0 commit comments