@@ -112,7 +112,8 @@ using namespace llvm;
112
112
RISCVRegisterBankInfo::RISCVRegisterBankInfo (unsigned HwMode)
113
113
: RISCVGenRegisterBankInfo(HwMode) {}
114
114
115
- static const RegisterBankInfo::ValueMapping *getFPValueMapping (unsigned Size) {
115
+ static const RegisterBankInfo::ValueMapping *
116
+ getFPValueMapping (unsigned Size, bool HasFPExt = true ) {
116
117
unsigned Idx;
117
118
switch (Size) {
118
119
default :
@@ -121,10 +122,10 @@ static const RegisterBankInfo::ValueMapping *getFPValueMapping(unsigned Size) {
121
122
Idx = RISCV::FPRB16Idx;
122
123
break ;
123
124
case 32 :
124
- Idx = RISCV::FPRB32Idx;
125
+ Idx = HasFPExt ? RISCV::FPRB32Idx : RISCV::GPRB32Idx ;
125
126
break ;
126
127
case 64 :
127
- Idx = RISCV::FPRB64Idx;
128
+ Idx = HasFPExt ? RISCV::FPRB64Idx : RISCV::GPRB64Idx ;
128
129
break ;
129
130
}
130
131
return &RISCV::ValueMappings[Idx];
@@ -219,6 +220,10 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
219
220
const TargetSubtargetInfo &STI = MF.getSubtarget ();
220
221
const TargetRegisterInfo &TRI = *STI.getRegisterInfo ();
221
222
223
+ bool HasFPExt = STI.hasFeature (RISCV::FeatureStdExtF) ||
224
+ STI.hasFeature (RISCV::FeatureStdExtD) ||
225
+ STI.hasFeature (RISCV::FeatureStdExtZfh);
226
+
222
227
unsigned GPRSize = getMaximumSize (RISCV::GPRBRegBankID);
223
228
assert ((GPRSize == 32 || GPRSize == 64 ) && " Unexpected GPR size" );
224
229
@@ -266,7 +271,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
266
271
if (Ty.isVector ())
267
272
Mapping = getVRBValueMapping (Size.getKnownMinValue ());
268
273
else if (isPreISelGenericFloatingPointOpcode (Opc))
269
- Mapping = getFPValueMapping (Size.getFixedValue ());
274
+ Mapping = getFPValueMapping (Size.getFixedValue (), HasFPExt );
270
275
else
271
276
Mapping = GPRValueMapping;
272
277
@@ -301,7 +306,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
301
306
if (DstTy.isVector ())
302
307
Mapping = getVRBValueMapping (DstMinSize);
303
308
else if (anyUseOnlyUseFP (Dst, MRI, TRI))
304
- Mapping = getFPValueMapping (DstMinSize);
309
+ Mapping = getFPValueMapping (DstMinSize, HasFPExt );
305
310
306
311
return getInstructionMapping (DefaultMappingID, /* Cost=*/ 1 , Mapping,
307
312
NumOperands);
@@ -339,7 +344,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
339
344
// assume this was a floating point load in the IR. If it was
340
345
// not, we would have had a bitcast before reaching that
341
346
// instruction.
342
- OpdsMapping[0 ] = getFPValueMapping (Size);
347
+ OpdsMapping[0 ] = getFPValueMapping (Size, HasFPExt );
343
348
break ;
344
349
}
345
350
@@ -367,7 +372,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
367
372
368
373
MachineInstr *DefMI = MRI.getVRegDef (MI.getOperand (0 ).getReg ());
369
374
if (onlyDefinesFP (*DefMI, MRI, TRI))
370
- OpdsMapping[0 ] = getFPValueMapping (Ty.getSizeInBits ());
375
+ OpdsMapping[0 ] = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
371
376
break ;
372
377
}
373
378
case TargetOpcode::G_SELECT: {
@@ -432,7 +437,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
432
437
433
438
const ValueMapping *Mapping = GPRValueMapping;
434
439
if (NumFP >= 2 )
435
- Mapping = getFPValueMapping (Ty.getSizeInBits ());
440
+ Mapping = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
436
441
437
442
OpdsMapping[0 ] = OpdsMapping[2 ] = OpdsMapping[3 ] = Mapping;
438
443
break ;
@@ -444,13 +449,13 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
444
449
case RISCV::G_FCLASS: {
445
450
LLT Ty = MRI.getType (MI.getOperand (1 ).getReg ());
446
451
OpdsMapping[0 ] = GPRValueMapping;
447
- OpdsMapping[1 ] = getFPValueMapping (Ty.getSizeInBits ());
452
+ OpdsMapping[1 ] = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
448
453
break ;
449
454
}
450
455
case TargetOpcode::G_SITOFP:
451
456
case TargetOpcode::G_UITOFP: {
452
457
LLT Ty = MRI.getType (MI.getOperand (0 ).getReg ());
453
- OpdsMapping[0 ] = getFPValueMapping (Ty.getSizeInBits ());
458
+ OpdsMapping[0 ] = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
454
459
OpdsMapping[1 ] = GPRValueMapping;
455
460
break ;
456
461
}
@@ -468,7 +473,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
468
473
LLT Ty = MRI.getType (MI.getOperand (0 ).getReg ());
469
474
if (GPRSize == 32 && Ty.getSizeInBits () == 64 ) {
470
475
assert (MF.getSubtarget <RISCVSubtarget>().hasStdExtD ());
471
- OpdsMapping[0 ] = getFPValueMapping (Ty.getSizeInBits ());
476
+ OpdsMapping[0 ] = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
472
477
OpdsMapping[1 ] = GPRValueMapping;
473
478
OpdsMapping[2 ] = GPRValueMapping;
474
479
}
@@ -481,7 +486,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
481
486
assert (MF.getSubtarget <RISCVSubtarget>().hasStdExtD ());
482
487
OpdsMapping[0 ] = GPRValueMapping;
483
488
OpdsMapping[1 ] = GPRValueMapping;
484
- OpdsMapping[2 ] = getFPValueMapping (Ty.getSizeInBits ());
489
+ OpdsMapping[2 ] = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
485
490
}
486
491
break ;
487
492
}
@@ -495,7 +500,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
495
500
if ((GPRSize == 32 && ScalarTy.getSizeInBits () == 64 ) ||
496
501
onlyDefinesFP (*DefMI, MRI, TRI)) {
497
502
assert (MF.getSubtarget <RISCVSubtarget>().hasStdExtD ());
498
- OpdsMapping[1 ] = getFPValueMapping (ScalarTy.getSizeInBits ());
503
+ OpdsMapping[1 ] = getFPValueMapping (ScalarTy.getSizeInBits (), HasFPExt );
499
504
} else
500
505
OpdsMapping[1 ] = GPRValueMapping;
501
506
break ;
@@ -514,7 +519,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
514
519
OpdsMapping[Idx] =
515
520
getVRBValueMapping (Ty.getSizeInBits ().getKnownMinValue ());
516
521
else if (isPreISelGenericFloatingPointOpcode (Opc))
517
- OpdsMapping[Idx] = getFPValueMapping (Ty.getSizeInBits ());
522
+ OpdsMapping[Idx] = getFPValueMapping (Ty.getSizeInBits (), HasFPExt );
518
523
else
519
524
OpdsMapping[Idx] = GPRValueMapping;
520
525
}
0 commit comments