@@ -112,7 +112,8 @@ using namespace llvm;
112112RISCVRegisterBankInfo::RISCVRegisterBankInfo (unsigned HwMode)
113113 : RISCVGenRegisterBankInfo(HwMode) {}
114114
115- static const RegisterBankInfo::ValueMapping *getFPValueMapping (unsigned Size) {
115+ static const RegisterBankInfo::ValueMapping *
116+ getFPValueMapping (unsigned Size, bool HasFPExt = true ) {
116117 unsigned Idx;
117118 switch (Size) {
118119 default :
@@ -121,10 +122,10 @@ static const RegisterBankInfo::ValueMapping *getFPValueMapping(unsigned Size) {
121122 Idx = RISCV::FPRB16Idx;
122123 break ;
123124 case 32 :
124- Idx = RISCV::FPRB32Idx;
125+ Idx = HasFPExt ? RISCV::FPRB32Idx : RISCV::GPRB32Idx ;
125126 break ;
126127 case 64 :
127- Idx = RISCV::FPRB64Idx;
128+ Idx = HasFPExt ? RISCV::FPRB64Idx : RISCV::GPRB64Idx ;
128129 break ;
129130 }
130131 return &RISCV::ValueMappings[Idx];
@@ -219,6 +220,10 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
219220 const TargetSubtargetInfo &STI = MF.getSubtarget ();
220221 const TargetRegisterInfo &TRI = *STI.getRegisterInfo ();
221222
223+ bool HasFPExt = STI.hasFeature (RISCV::FeatureStdExtF) ||
224+ STI.hasFeature (RISCV::FeatureStdExtD) ||
225+ STI.hasFeature (RISCV::FeatureStdExtZfh);
226+
222227 unsigned GPRSize = getMaximumSize (RISCV::GPRBRegBankID);
223228 assert ((GPRSize == 32 || GPRSize == 64 ) && " Unexpected GPR size" );
224229
@@ -266,7 +271,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
266271 if (Ty.isVector ())
267272 Mapping = getVRBValueMapping (Size.getKnownMinValue ());
268273 else if (isPreISelGenericFloatingPointOpcode (Opc))
269- Mapping = getFPValueMapping (Size.getFixedValue ());
274+ Mapping = getFPValueMapping (Size.getFixedValue (), HasFPExt );
270275 else
271276 Mapping = GPRValueMapping;
272277
@@ -301,7 +306,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
301306 if (DstTy.isVector ())
302307 Mapping = getVRBValueMapping (DstMinSize);
303308 else if (anyUseOnlyUseFP (Dst, MRI, TRI))
304- Mapping = getFPValueMapping (DstMinSize);
309+ Mapping = getFPValueMapping (DstMinSize, HasFPExt );
305310
306311 return getInstructionMapping (DefaultMappingID, /* Cost=*/ 1 , Mapping,
307312 NumOperands);
@@ -339,7 +344,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
339344 // assume this was a floating point load in the IR. If it was
340345 // not, we would have had a bitcast before reaching that
341346 // instruction.
342- OpdsMapping[0 ] = getFPValueMapping (Size);
347+ OpdsMapping[0 ] = getFPValueMapping (Size, HasFPExt );
343348 break ;
344349 }
345350
@@ -367,7 +372,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
367372
368373 MachineInstr *DefMI = MRI.getVRegDef (MI.getOperand (0 ).getReg ());
369374 if (onlyDefinesFP (*DefMI, MRI, TRI))
370- OpdsMapping[0 ] = getFPValueMapping (Ty.getSizeInBits ());
375+ OpdsMapping[0 ] = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
371376 break ;
372377 }
373378 case TargetOpcode::G_SELECT: {
@@ -432,7 +437,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
432437
433438 const ValueMapping *Mapping = GPRValueMapping;
434439 if (NumFP >= 2 )
435- Mapping = getFPValueMapping (Ty.getSizeInBits ());
440+ Mapping = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
436441
437442 OpdsMapping[0 ] = OpdsMapping[2 ] = OpdsMapping[3 ] = Mapping;
438443 break ;
@@ -444,13 +449,13 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
444449 case RISCV::G_FCLASS: {
445450 LLT Ty = MRI.getType (MI.getOperand (1 ).getReg ());
446451 OpdsMapping[0 ] = GPRValueMapping;
447- OpdsMapping[1 ] = getFPValueMapping (Ty.getSizeInBits ());
452+ OpdsMapping[1 ] = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
448453 break ;
449454 }
450455 case TargetOpcode::G_SITOFP:
451456 case TargetOpcode::G_UITOFP: {
452457 LLT Ty = MRI.getType (MI.getOperand (0 ).getReg ());
453- OpdsMapping[0 ] = getFPValueMapping (Ty.getSizeInBits ());
458+ OpdsMapping[0 ] = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
454459 OpdsMapping[1 ] = GPRValueMapping;
455460 break ;
456461 }
@@ -468,7 +473,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
468473 LLT Ty = MRI.getType (MI.getOperand (0 ).getReg ());
469474 if (GPRSize == 32 && Ty.getSizeInBits () == 64 ) {
470475 assert (MF.getSubtarget <RISCVSubtarget>().hasStdExtD ());
471- OpdsMapping[0 ] = getFPValueMapping (Ty.getSizeInBits ());
476+ OpdsMapping[0 ] = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
472477 OpdsMapping[1 ] = GPRValueMapping;
473478 OpdsMapping[2 ] = GPRValueMapping;
474479 }
@@ -481,7 +486,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
481486 assert (MF.getSubtarget <RISCVSubtarget>().hasStdExtD ());
482487 OpdsMapping[0 ] = GPRValueMapping;
483488 OpdsMapping[1 ] = GPRValueMapping;
484- OpdsMapping[2 ] = getFPValueMapping (Ty.getSizeInBits ());
489+ OpdsMapping[2 ] = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
485490 }
486491 break ;
487492 }
@@ -495,7 +500,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
495500 if ((GPRSize == 32 && ScalarTy.getSizeInBits () == 64 ) ||
496501 onlyDefinesFP (*DefMI, MRI, TRI)) {
497502 assert (MF.getSubtarget <RISCVSubtarget>().hasStdExtD ());
498- OpdsMapping[1 ] = getFPValueMapping (ScalarTy.getSizeInBits ());
503+ OpdsMapping[1 ] = getFPValueMapping (ScalarTy.getSizeInBits (), HasFPExt );
499504 } else
500505 OpdsMapping[1 ] = GPRValueMapping;
501506 break ;
@@ -514,7 +519,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
514519 OpdsMapping[Idx] =
515520 getVRBValueMapping (Ty.getSizeInBits ().getKnownMinValue ());
516521 else if (isPreISelGenericFloatingPointOpcode (Opc))
517- OpdsMapping[Idx] = getFPValueMapping (Ty.getSizeInBits ());
522+ OpdsMapping[Idx] = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
518523 else
519524 OpdsMapping[Idx] = GPRValueMapping;
520525 }
0 commit comments