@@ -444,12 +444,10 @@ DemandedFields getDemanded(const MachineInstr &MI,
444
444
// / values of the VL and VTYPE registers after insertion.
445
445
class VSETVLIInfo {
446
446
union {
447
- Register AVLReg ;
447
+ const MachineInstr *AVLDefMI ;
448
448
unsigned AVLImm;
449
449
};
450
450
451
- const MachineInstr *AVLDefMI;
452
-
453
451
enum : uint8_t {
454
452
Uninitialized,
455
453
AVLIsDefMI,
@@ -468,7 +466,7 @@ class VSETVLIInfo {
468
466
469
467
public:
470
468
VSETVLIInfo ()
471
- : AVLImm(0 ), AVLDefMI( nullptr ), TailAgnostic(false ), MaskAgnostic(false ),
469
+ : AVLImm(0 ), TailAgnostic(false ), MaskAgnostic(false ),
472
470
SEWLMULRatioOnly (false ) {}
473
471
474
472
static VSETVLIInfo getUnknown () {
@@ -481,9 +479,8 @@ class VSETVLIInfo {
481
479
void setUnknown () { State = Unknown; }
482
480
bool isUnknown () const { return State == Unknown; }
483
481
484
- void setAVLReg (Register Reg, const MachineInstr *DefMI) {
485
- assert (Reg.isVirtual ());
486
- AVLReg = Reg;
482
+ void setAVLDefMI (const MachineInstr *DefMI) {
483
+ assert (DefMI);
487
484
AVLDefMI = DefMI;
488
485
State = AVLIsDefMI;
489
486
}
@@ -496,29 +493,31 @@ class VSETVLIInfo {
496
493
void setAVLVLMAX () { State = AVLIsVLMAX; }
497
494
498
495
void setAVLIgnored () { State = AVLIsIgnored; }
499
- void setAVLDefMI (const MachineInstr *DefMI) { AVLDefMI = DefMI; }
500
496
501
497
bool hasAVLImm () const { return State == AVLIsImm; }
502
- bool hasAVLReg () const { return State == AVLIsDefMI; }
498
+ bool hasAVLDefMI () const { return State == AVLIsDefMI; }
503
499
bool hasAVLVLMAX () const { return State == AVLIsVLMAX; }
504
500
bool hasAVLIgnored () const { return State == AVLIsIgnored; }
505
501
Register getAVLReg () const {
506
- assert (hasAVLReg ());
507
- return AVLReg ;
502
+ assert (hasAVLDefMI ());
503
+ return AVLDefMI-> getOperand ( 0 ). getReg () ;
508
504
}
509
505
unsigned getAVLImm () const {
510
506
assert (hasAVLImm ());
511
507
return AVLImm;
512
508
}
513
509
514
- const MachineInstr *getAVLDefMI () const { return AVLDefMI; }
510
+ const MachineInstr *getAVLDefMI () const {
511
+ assert (AVLDefMI);
512
+ return AVLDefMI;
513
+ }
515
514
516
515
void setAVL (VSETVLIInfo Info) {
517
516
assert (Info.isValid ());
518
517
if (Info.isUnknown ())
519
518
setUnknown ();
520
- else if (Info.hasAVLReg ())
521
- setAVLReg (Info. getAVLReg (), Info.getAVLDefMI ());
519
+ else if (Info.hasAVLDefMI ())
520
+ setAVLDefMI ( Info.getAVLDefMI ());
522
521
else if (Info.hasAVLVLMAX ())
523
522
setAVLVLMAX ();
524
523
else if (Info.hasAVLIgnored ())
@@ -537,7 +536,7 @@ class VSETVLIInfo {
537
536
bool hasNonZeroAVL () const {
538
537
if (hasAVLImm ())
539
538
return getAVLImm () > 0 ;
540
- if (hasAVLReg ()) {
539
+ if (hasAVLDefMI ()) {
541
540
const MachineInstr *MI = getAVLDefMI ();
542
541
assert (MI);
543
542
return isNonZeroLoadImmediate (*MI);
@@ -556,8 +555,8 @@ class VSETVLIInfo {
556
555
}
557
556
558
557
bool hasSameAVL (const VSETVLIInfo &Other) const {
559
- if (hasAVLReg () && Other.hasAVLReg ())
560
- return getAVLReg () == Other.getAVLReg ( );
558
+ if (hasAVLDefMI () && Other.hasAVLDefMI ())
559
+ return getAVLDefMI ()-> isIdenticalTo (* Other.getAVLDefMI () );
561
560
562
561
if (hasAVLImm () && Other.hasAVLImm ())
563
562
return getAVLImm () == Other.getAVLImm ();
@@ -737,8 +736,8 @@ class VSETVLIInfo {
737
736
OS << " Uninitialized" ;
738
737
if (isUnknown ())
739
738
OS << " unknown" ;
740
- if (hasAVLReg ())
741
- OS << " AVLReg=" << (unsigned )AVLReg ;
739
+ if (hasAVLDefMI ())
740
+ OS << " AVLReg=" << (unsigned )getAVLReg () ;
742
741
if (hasAVLImm ())
743
742
OS << " AVLImm=" << (unsigned )AVLImm;
744
743
if (hasAVLVLMAX ())
@@ -878,7 +877,7 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
878
877
if (AVLReg == RISCV::X0)
879
878
NewInfo.setAVLVLMAX ();
880
879
else
881
- NewInfo.setAVLReg (AVLReg, MRI.getVRegDef (AVLReg));
880
+ NewInfo.setAVLDefMI ( MRI.getVRegDef (AVLReg));
882
881
}
883
882
NewInfo.setVTYPE (MI.getOperand (2 ).getImm ());
884
883
@@ -950,9 +949,7 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
950
949
else
951
950
InstrInfo.setAVLImm (Imm);
952
951
} else {
953
- InstrInfo.setAVLReg (VLOp.getReg (), VLOp.getReg ().isVirtual ()
954
- ? MRI->getVRegDef (VLOp.getReg ())
955
- : nullptr );
952
+ InstrInfo.setAVLDefMI (MRI->getVRegDef (VLOp.getReg ()));
956
953
}
957
954
} else {
958
955
assert (isScalarExtractInstr (MI));
@@ -972,7 +969,7 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
972
969
// AVL operand with the AVL of the defining vsetvli. We avoid general
973
970
// register AVLs to avoid extending live ranges without being sure we can
974
971
// kill the original source reg entirely.
975
- if (InstrInfo.hasAVLReg ()) {
972
+ if (InstrInfo.hasAVLDefMI ()) {
976
973
const MachineInstr *DefMI = InstrInfo.getAVLDefMI ();
977
974
if (DefMI && isVectorConfigInstr (*DefMI)) {
978
975
VSETVLIInfo DefInstrInfo = getInfoForVSETVLI (*DefMI, *MRI);
@@ -1012,7 +1009,7 @@ void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
1012
1009
// If our AVL is a virtual register, it might be defined by a VSET(I)VLI. If
1013
1010
// it has the same VLMAX we want and the last VL/VTYPE we observed is the
1014
1011
// same, we can use the X0, X0 form.
1015
- if (Info.hasSameVLMAX (PrevInfo) && Info.hasAVLReg ()) {
1012
+ if (Info.hasSameVLMAX (PrevInfo) && Info.hasAVLDefMI ()) {
1016
1013
const MachineInstr *DefMI = Info.getAVLDefMI ();
1017
1014
assert (DefMI);
1018
1015
if (isVectorConfigInstr (*DefMI)) {
@@ -1131,11 +1128,11 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
1131
1128
// it might be defined by a VSET(I)VLI. If it has the same VLMAX we need
1132
1129
// and the last VL/VTYPE we observed is the same, we don't need a
1133
1130
// VSETVLI here.
1134
- if (Require.hasAVLReg () && CurInfo.hasCompatibleVTYPE (Used, Require)) {
1135
- MachineInstr *DefMI = MRI-> getUniqueVRegDef ( Require.getAVLReg () );
1131
+ if (Require.hasAVLDefMI () && CurInfo.hasCompatibleVTYPE (Used, Require)) {
1132
+ const MachineInstr *DefMI = Require.getAVLDefMI ( );
1136
1133
assert (DefMI);
1137
- if (Require. getAVLDefMI () && isVectorConfigInstr (*Require. getAVLDefMI () )) {
1138
- VSETVLIInfo DefInfo = getInfoForVSETVLI (*Require. getAVLDefMI () , *MRI);
1134
+ if (DefMI && isVectorConfigInstr (*DefMI )) {
1135
+ VSETVLIInfo DefInfo = getInfoForVSETVLI (*DefMI , *MRI);
1139
1136
if (DefInfo.hasSameAVL (CurInfo) && DefInfo.hasSameVLMAX (CurInfo))
1140
1137
return false ;
1141
1138
}
@@ -1227,10 +1224,7 @@ void RISCVInsertVSETVLI::transferAfter(VSETVLIInfo &Info,
1227
1224
1228
1225
if (RISCV::isFaultFirstLoad (MI)) {
1229
1226
// Update AVL to vl-output of the fault first load.
1230
- Info.setAVLReg (MI.getOperand (1 ).getReg (),
1231
- MI.getOperand (1 ).getReg ().isVirtual ()
1232
- ? MRI->getVRegDef (MI.getOperand (1 ).getReg ())
1233
- : nullptr );
1227
+ Info.setAVLDefMI (MRI->getVRegDef (MI.getOperand (1 ).getReg ()));
1234
1228
return ;
1235
1229
}
1236
1230
@@ -1321,15 +1315,11 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require,
1321
1315
if (DisableInsertVSETVLPHIOpt)
1322
1316
return true ;
1323
1317
1324
- if (!Require.hasAVLReg ())
1325
- return true ;
1326
-
1327
- Register AVLReg = Require.getAVLReg ();
1328
- if (!AVLReg.isVirtual ())
1318
+ if (!Require.hasAVLDefMI ())
1329
1319
return true ;
1330
1320
1331
1321
// We need the AVL to be produce by a PHI node in this basic block.
1332
- MachineInstr *PHI = MRI-> getVRegDef (AVLReg );
1322
+ const MachineInstr *PHI = Require. getAVLDefMI ( );
1333
1323
if (!PHI || PHI->getOpcode () != RISCV::PHI || PHI->getParent () != &MBB)
1334
1324
return true ;
1335
1325
@@ -1498,7 +1488,7 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
1498
1488
// If the AVL value is a register (other than our VLMAX sentinel),
1499
1489
// we need to prove the value is available at the point we're going
1500
1490
// to insert the vsetvli at.
1501
- if (AvailableInfo.hasAVLReg ()) {
1491
+ if (AvailableInfo.hasAVLDefMI ()) {
1502
1492
const MachineInstr *AVLDefMI = AvailableInfo.getAVLDefMI ();
1503
1493
assert (AVLDefMI);
1504
1494
// This is an inline dominance check which covers the case of
0 commit comments