@@ -455,12 +455,10 @@ DemandedFields getDemanded(const MachineInstr &MI,
455
455
// / values of the VL and VTYPE registers after insertion.
456
456
class VSETVLIInfo {
457
457
union {
458
- Register AVLReg ;
458
+ const MachineInstr *AVLDefMI ;
459
459
unsigned AVLImm;
460
460
};
461
461
462
- const MachineInstr *AVLDefMI;
463
-
464
462
enum : uint8_t {
465
463
Uninitialized,
466
464
AVLIsDefMI,
@@ -479,7 +477,7 @@ class VSETVLIInfo {
479
477
480
478
public:
481
479
VSETVLIInfo ()
482
- : AVLImm(0 ), AVLDefMI( nullptr ), TailAgnostic(false ), MaskAgnostic(false ),
480
+ : AVLImm(0 ), TailAgnostic(false ), MaskAgnostic(false ),
483
481
SEWLMULRatioOnly (false ) {}
484
482
485
483
static VSETVLIInfo getUnknown () {
@@ -492,9 +490,8 @@ class VSETVLIInfo {
492
490
void setUnknown () { State = Unknown; }
493
491
bool isUnknown () const { return State == Unknown; }
494
492
495
- void setAVLReg (Register Reg, const MachineInstr *DefMI) {
496
- assert (Reg.isVirtual ());
497
- AVLReg = Reg;
493
+ void setAVLDefMI (const MachineInstr *DefMI) {
494
+ assert (DefMI);
498
495
AVLDefMI = DefMI;
499
496
State = AVLIsDefMI;
500
497
}
@@ -507,29 +504,31 @@ class VSETVLIInfo {
507
504
void setAVLVLMAX () { State = AVLIsVLMAX; }
508
505
509
506
void setAVLIgnored () { State = AVLIsIgnored; }
510
- void setAVLDefMI (const MachineInstr *DefMI) { AVLDefMI = DefMI; }
511
507
512
508
bool hasAVLImm () const { return State == AVLIsImm; }
513
- bool hasAVLReg () const { return State == AVLIsDefMI; }
509
+ bool hasAVLDefMI () const { return State == AVLIsDefMI; }
514
510
bool hasAVLVLMAX () const { return State == AVLIsVLMAX; }
515
511
bool hasAVLIgnored () const { return State == AVLIsIgnored; }
516
512
Register getAVLReg () const {
517
- assert (hasAVLReg ());
518
- return AVLReg ;
513
+ assert (hasAVLDefMI ());
514
+ return AVLDefMI-> getOperand ( 0 ). getReg () ;
519
515
}
520
516
unsigned getAVLImm () const {
521
517
assert (hasAVLImm ());
522
518
return AVLImm;
523
519
}
524
520
525
- const MachineInstr *getAVLDefMI () const { return AVLDefMI; }
521
+ const MachineInstr *getAVLDefMI () const {
522
+ assert (AVLDefMI);
523
+ return AVLDefMI;
524
+ }
526
525
527
526
void setAVL (VSETVLIInfo Info) {
528
527
assert (Info.isValid ());
529
528
if (Info.isUnknown ())
530
529
setUnknown ();
531
- else if (Info.hasAVLReg ())
532
- setAVLReg (Info. getAVLReg (), Info.getAVLDefMI ());
530
+ else if (Info.hasAVLDefMI ())
531
+ setAVLDefMI ( Info.getAVLDefMI ());
533
532
else if (Info.hasAVLVLMAX ())
534
533
setAVLVLMAX ();
535
534
else if (Info.hasAVLIgnored ())
@@ -548,7 +547,7 @@ class VSETVLIInfo {
548
547
bool hasNonZeroAVL () const {
549
548
if (hasAVLImm ())
550
549
return getAVLImm () > 0 ;
551
- if (hasAVLReg ()) {
550
+ if (hasAVLDefMI ()) {
552
551
const MachineInstr *MI = getAVLDefMI ();
553
552
assert (MI);
554
553
return isNonZeroLoadImmediate (*MI);
@@ -567,8 +566,8 @@ class VSETVLIInfo {
567
566
}
568
567
569
568
bool hasSameAVL (const VSETVLIInfo &Other) const {
570
- if (hasAVLReg () && Other.hasAVLReg ())
571
- return getAVLReg () == Other.getAVLReg ( );
569
+ if (hasAVLDefMI () && Other.hasAVLDefMI ())
570
+ return getAVLDefMI ()-> isIdenticalTo (* Other.getAVLDefMI () );
572
571
573
572
if (hasAVLImm () && Other.hasAVLImm ())
574
573
return getAVLImm () == Other.getAVLImm ();
@@ -748,8 +747,8 @@ class VSETVLIInfo {
748
747
OS << " Uninitialized" ;
749
748
if (isUnknown ())
750
749
OS << " unknown" ;
751
- if (hasAVLReg ())
752
- OS << " AVLReg=" << (unsigned )AVLReg ;
750
+ if (hasAVLDefMI ())
751
+ OS << " AVLReg=" << (unsigned )getAVLReg () ;
753
752
if (hasAVLImm ())
754
753
OS << " AVLImm=" << (unsigned )AVLImm;
755
754
if (hasAVLVLMAX ())
@@ -889,7 +888,7 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
889
888
if (AVLReg == RISCV::X0)
890
889
NewInfo.setAVLVLMAX ();
891
890
else
892
- NewInfo.setAVLReg (AVLReg, MRI.getVRegDef (AVLReg));
891
+ NewInfo.setAVLDefMI ( MRI.getVRegDef (AVLReg));
893
892
}
894
893
NewInfo.setVTYPE (MI.getOperand (2 ).getImm ());
895
894
@@ -961,9 +960,7 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
961
960
else
962
961
InstrInfo.setAVLImm (Imm);
963
962
} else {
964
- InstrInfo.setAVLReg (VLOp.getReg (), VLOp.getReg ().isVirtual ()
965
- ? MRI->getVRegDef (VLOp.getReg ())
966
- : nullptr );
963
+ InstrInfo.setAVLDefMI (MRI->getVRegDef (VLOp.getReg ()));
967
964
}
968
965
} else {
969
966
assert (isScalarExtractInstr (MI));
@@ -983,7 +980,7 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
983
980
// AVL operand with the AVL of the defining vsetvli. We avoid general
984
981
// register AVLs to avoid extending live ranges without being sure we can
985
982
// kill the original source reg entirely.
986
- if (InstrInfo.hasAVLReg ()) {
983
+ if (InstrInfo.hasAVLDefMI ()) {
987
984
const MachineInstr *DefMI = InstrInfo.getAVLDefMI ();
988
985
if (isVectorConfigInstr (*DefMI)) {
989
986
VSETVLIInfo DefInstrInfo = getInfoForVSETVLI (*DefMI, *MRI);
@@ -1023,7 +1020,7 @@ void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
1023
1020
// If our AVL is a virtual register, it might be defined by a VSET(I)VLI. If
1024
1021
// it has the same VLMAX we want and the last VL/VTYPE we observed is the
1025
1022
// same, we can use the X0, X0 form.
1026
- if (Info.hasSameVLMAX (PrevInfo) && Info.hasAVLReg ()) {
1023
+ if (Info.hasSameVLMAX (PrevInfo) && Info.hasAVLDefMI ()) {
1027
1024
const MachineInstr *DefMI = Info.getAVLDefMI ();
1028
1025
assert (DefMI);
1029
1026
if (isVectorConfigInstr (*DefMI)) {
@@ -1142,11 +1139,11 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
1142
1139
// it might be defined by a VSET(I)VLI. If it has the same VLMAX we need
1143
1140
// and the last VL/VTYPE we observed is the same, we don't need a
1144
1141
// VSETVLI here.
1145
- if (Require.hasAVLReg () && CurInfo.hasCompatibleVTYPE (Used, Require)) {
1146
- MachineInstr *DefMI = MRI-> getUniqueVRegDef ( Require.getAVLReg () );
1142
+ if (Require.hasAVLDefMI () && CurInfo.hasCompatibleVTYPE (Used, Require)) {
1143
+ const MachineInstr *DefMI = Require.getAVLDefMI ( );
1147
1144
assert (DefMI);
1148
- if (Require. getAVLDefMI () && isVectorConfigInstr (*Require. getAVLDefMI () )) {
1149
- VSETVLIInfo DefInfo = getInfoForVSETVLI (*Require. getAVLDefMI () , *MRI);
1145
+ if (DefMI && isVectorConfigInstr (*DefMI )) {
1146
+ VSETVLIInfo DefInfo = getInfoForVSETVLI (*DefMI , *MRI);
1150
1147
if (DefInfo.hasSameAVL (CurInfo) && DefInfo.hasSameVLMAX (CurInfo))
1151
1148
return false ;
1152
1149
}
@@ -1238,10 +1235,7 @@ void RISCVInsertVSETVLI::transferAfter(VSETVLIInfo &Info,
1238
1235
1239
1236
if (RISCV::isFaultFirstLoad (MI)) {
1240
1237
// Update AVL to vl-output of the fault first load.
1241
- Info.setAVLReg (MI.getOperand (1 ).getReg (),
1242
- MI.getOperand (1 ).getReg ().isVirtual ()
1243
- ? MRI->getVRegDef (MI.getOperand (1 ).getReg ())
1244
- : nullptr );
1238
+ Info.setAVLDefMI (MRI->getVRegDef (MI.getOperand (1 ).getReg ()));
1245
1239
return ;
1246
1240
}
1247
1241
@@ -1332,14 +1326,11 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require,
1332
1326
if (DisableInsertVSETVLPHIOpt)
1333
1327
return true ;
1334
1328
1335
- if (!Require.hasAVLReg ())
1329
+ if (!Require.hasAVLDefMI ())
1336
1330
return true ;
1337
1331
1338
- Register AVLReg = Require.getAVLReg ();
1339
-
1340
1332
// We need the AVL to be produce by a PHI node in this basic block.
1341
- MachineInstr *PHI = MRI->getUniqueVRegDef (AVLReg);
1342
- assert (PHI);
1333
+ const MachineInstr *PHI = Require.getAVLDefMI ();
1343
1334
if (PHI->getOpcode () != RISCV::PHI || PHI->getParent () != &MBB)
1344
1335
return true ;
1345
1336
@@ -1509,7 +1500,7 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
1509
1500
// If the AVL value is a register (other than our VLMAX sentinel),
1510
1501
// we need to prove the value is available at the point we're going
1511
1502
// to insert the vsetvli at.
1512
- if (AvailableInfo.hasAVLReg ()) {
1503
+ if (AvailableInfo.hasAVLDefMI ()) {
1513
1504
const MachineInstr *AVLDefMI = AvailableInfo.getAVLDefMI ();
1514
1505
assert (AVLDefMI);
1515
1506
// This is an inline dominance check which covers the case of
0 commit comments