@@ -753,6 +753,7 @@ bool RISCVRegisterInfo::getRegAllocationHints(
753
753
SmallVectorImpl<MCPhysReg> &Hints, const MachineFunction &MF,
754
754
const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const {
755
755
const MachineRegisterInfo *MRI = &MF.getRegInfo ();
756
+ auto &Subtarget = MF.getSubtarget <RISCVSubtarget>();
756
757
757
758
bool BaseImplRetVal = TargetRegisterInfo::getRegAllocationHints (
758
759
VirtReg, Order, Hints, MF, VRM, Matrix);
@@ -776,7 +777,7 @@ bool RISCVRegisterInfo::getRegAllocationHints(
776
777
777
778
// This is all of the compressible binary instructions. If an instruction
778
779
// 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) {
780
781
NeedGPRC = false ;
781
782
switch (MI.getOpcode ()) {
782
783
default :
@@ -789,9 +790,16 @@ bool RISCVRegisterInfo::getRegAllocationHints(
789
790
case RISCV::SUBW:
790
791
NeedGPRC = true ;
791
792
return true ;
792
- case RISCV::ANDI:
793
+ case RISCV::ANDI: {
793
794
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
+ }
795
803
case RISCV::SRAI:
796
804
case RISCV::SRLI:
797
805
NeedGPRC = true ;
@@ -802,6 +810,24 @@ bool RISCVRegisterInfo::getRegAllocationHints(
802
810
case RISCV::ADDI:
803
811
case RISCV::ADDIW:
804
812
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 ;
805
831
}
806
832
};
807
833
@@ -823,13 +849,15 @@ bool RISCVRegisterInfo::getRegAllocationHints(
823
849
bool NeedGPRC;
824
850
if (isCompressible (MI, NeedGPRC)) {
825
851
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 )))
827
855
tryAddHint (MO, MI.getOperand (1 ), NeedGPRC);
828
856
if (MI.isCommutable () && MI.getOperand (2 ).isReg () &&
829
857
(!NeedGPRC || isCompressibleOpnd (MI.getOperand (1 ))))
830
858
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 )))) {
833
861
tryAddHint (MO, MI.getOperand (0 ), NeedGPRC);
834
862
} else if (MI.isCommutable () && OpIdx == 2 &&
835
863
(!NeedGPRC || isCompressibleOpnd (MI.getOperand (1 )))) {
0 commit comments