@@ -753,6 +753,7 @@ bool RISCVRegisterInfo::getRegAllocationHints(
753753 SmallVectorImpl<MCPhysReg> &Hints, const MachineFunction &MF,
754754 const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const {
755755 const MachineRegisterInfo *MRI = &MF.getRegInfo ();
756+ auto &Subtarget = MF.getSubtarget <RISCVSubtarget>();
756757
757758 bool BaseImplRetVal = TargetRegisterInfo::getRegAllocationHints (
758759 VirtReg, Order, Hints, MF, VRM, Matrix);
@@ -776,7 +777,7 @@ bool RISCVRegisterInfo::getRegAllocationHints(
776777
777778 // This is all of the compressible binary instructions. If an instruction
778779 // needs GPRC register class operands \p NeedGPRC will be set to true.
779- auto isCompressible = [](const MachineInstr &MI, bool &NeedGPRC) {
780+ auto isCompressible = [&Subtarget ](const MachineInstr &MI, bool &NeedGPRC) {
780781 NeedGPRC = false ;
781782 switch (MI.getOpcode ()) {
782783 default :
@@ -789,9 +790,16 @@ bool RISCVRegisterInfo::getRegAllocationHints(
789790 case RISCV::SUBW:
790791 NeedGPRC = true ;
791792 return true ;
792- case RISCV::ANDI:
793+ case RISCV::ANDI: {
793794 NeedGPRC = true ;
794- return MI.getOperand (2 ).isImm () && isInt<6 >(MI.getOperand (2 ).getImm ());
795+ if (!MI.getOperand (2 ).isImm ())
796+ return false ;
797+ int64_t Imm = MI.getOperand (2 ).getImm ();
798+ if (isInt<6 >(Imm))
799+ return true ;
800+ // c.zext.b
801+ return Subtarget.hasStdExtZcb () && Imm == 255 ;
802+ }
795803 case RISCV::SRAI:
796804 case RISCV::SRLI:
797805 NeedGPRC = true ;
@@ -802,6 +810,24 @@ bool RISCVRegisterInfo::getRegAllocationHints(
802810 case RISCV::ADDI:
803811 case RISCV::ADDIW:
804812 return MI.getOperand (2 ).isImm () && isInt<6 >(MI.getOperand (2 ).getImm ());
813+ case RISCV::MUL:
814+ case RISCV::SEXT_B:
815+ case RISCV::SEXT_H:
816+ case RISCV::ZEXT_H_RV32:
817+ case RISCV::ZEXT_H_RV64:
818+ // c.mul, c.sext.b, c.sext.h, c.zext.h
819+ NeedGPRC = true ;
820+ return Subtarget.hasStdExtZcb ();
821+ case RISCV::ADD_UW:
822+ // c.zext.w
823+ NeedGPRC = true ;
824+ return Subtarget.hasStdExtZcb () && MI.getOperand (2 ).isReg () &&
825+ MI.getOperand (2 ).getReg () == RISCV::X0;
826+ case RISCV::XORI:
827+ // c.not
828+ NeedGPRC = true ;
829+ return Subtarget.hasStdExtZcb () && MI.getOperand (2 ).isImm () &&
830+ MI.getOperand (2 ).getImm () == -1 ;
805831 }
806832 };
807833
@@ -823,13 +849,15 @@ bool RISCVRegisterInfo::getRegAllocationHints(
823849 bool NeedGPRC;
824850 if (isCompressible (MI, NeedGPRC)) {
825851 if (OpIdx == 0 && MI.getOperand (1 ).isReg ()) {
826- if (!NeedGPRC || isCompressibleOpnd (MI.getOperand (2 )))
852+ if (!NeedGPRC || MI.getNumExplicitOperands () < 3 ||
853+ MI.getOpcode () == RISCV::ADD_UW ||
854+ isCompressibleOpnd (MI.getOperand (2 )))
827855 tryAddHint (MO, MI.getOperand (1 ), NeedGPRC);
828856 if (MI.isCommutable () && MI.getOperand (2 ).isReg () &&
829857 (!NeedGPRC || isCompressibleOpnd (MI.getOperand (1 ))))
830858 tryAddHint (MO, MI.getOperand (2 ), NeedGPRC);
831- } else if (OpIdx == 1 &&
832- (!NeedGPRC || isCompressibleOpnd (MI.getOperand (2 )))) {
859+ } else if (OpIdx == 1 && (!NeedGPRC || MI. getNumExplicitOperands () < 3 ||
860+ isCompressibleOpnd (MI.getOperand (2 )))) {
833861 tryAddHint (MO, MI.getOperand (0 ), NeedGPRC);
834862 } else if (MI.isCommutable () && OpIdx == 2 &&
835863 (!NeedGPRC || isCompressibleOpnd (MI.getOperand (1 )))) {
0 commit comments