@@ -156,7 +156,7 @@ static std::optional<unsigned> getEEWForLoadStore(const MachineInstr &MI) {
156
156
}
157
157
}
158
158
159
- static bool isNonZeroLoadImmediate (MachineInstr &MI) {
159
+ static bool isNonZeroLoadImmediate (const MachineInstr &MI) {
160
160
return MI.getOpcode () == RISCV::ADDI &&
161
161
MI.getOperand (1 ).isReg () && MI.getOperand (2 ).isImm () &&
162
162
MI.getOperand (1 ).getReg () == RISCV::X0 &&
@@ -459,6 +459,8 @@ class VSETVLIInfo {
459
459
unsigned AVLImm;
460
460
};
461
461
462
+ const MachineInstr *AVLDefMI;
463
+
462
464
enum : uint8_t {
463
465
Uninitialized,
464
466
AVLIsReg,
@@ -477,7 +479,7 @@ class VSETVLIInfo {
477
479
478
480
public:
479
481
VSETVLIInfo ()
480
- : AVLImm(0 ), TailAgnostic(false ), MaskAgnostic(false ),
482
+ : AVLImm(0 ), AVLDefMI( nullptr ), TailAgnostic(false ), MaskAgnostic(false ),
481
483
SEWLMULRatioOnly (false ) {}
482
484
483
485
static VSETVLIInfo getUnknown () {
@@ -504,6 +506,7 @@ class VSETVLIInfo {
504
506
void setAVLVLMAX () { State = AVLIsVLMAX; }
505
507
506
508
void setAVLIgnored () { State = AVLIsIgnored; }
509
+ void setAVLDefMI (const MachineInstr *DefMI) { AVLDefMI = DefMI; }
507
510
508
511
bool hasAVLImm () const { return State == AVLIsImm; }
509
512
bool hasAVLReg () const { return State == AVLIsReg; }
@@ -518,12 +521,16 @@ class VSETVLIInfo {
518
521
return AVLImm;
519
522
}
520
523
524
+ const MachineInstr *getAVLDefMI () const { return AVLDefMI; }
525
+
521
526
void setAVL (VSETVLIInfo Info) {
522
527
assert (Info.isValid ());
523
528
if (Info.isUnknown ())
524
529
setUnknown ();
525
- else if (Info.hasAVLReg ())
530
+ else if (Info.hasAVLReg ()) {
526
531
setAVLReg (Info.getAVLReg ());
532
+ setAVLDefMI (Info.getAVLDefMI ());
533
+ }
527
534
else if (Info.hasAVLVLMAX ())
528
535
setAVLVLMAX ();
529
536
else if (Info.hasAVLIgnored ())
@@ -543,7 +550,7 @@ class VSETVLIInfo {
543
550
if (hasAVLImm ())
544
551
return getAVLImm () > 0 ;
545
552
if (hasAVLReg ()) {
546
- MachineInstr *MI = MRI. getUniqueVRegDef ( getAVLReg () );
553
+ const MachineInstr *MI = getAVLDefMI ( );
547
554
assert (MI);
548
555
return isNonZeroLoadImmediate (*MI);
549
556
}
@@ -870,7 +877,8 @@ INITIALIZE_PASS(RISCVCoalesceVSETVLI, "riscv-coalesce-vsetvli",
870
877
871
878
// Return a VSETVLIInfo representing the changes made by this VSETVLI or
872
879
// VSETIVLI instruction.
873
- static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI) {
880
+ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
881
+ const MachineRegisterInfo &MRI) {
874
882
VSETVLIInfo NewInfo;
875
883
if (MI.getOpcode () == RISCV::PseudoVSETIVLI) {
876
884
NewInfo.setAVLImm (MI.getOperand (1 ).getImm ());
@@ -883,7 +891,7 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI) {
883
891
if (AVLReg == RISCV::X0)
884
892
NewInfo.setAVLVLMAX ();
885
893
else
886
- NewInfo.setAVLReg ( AVLReg);
894
+ NewInfo.setAVLDefMI (MRI. getVRegDef ( AVLReg) );
887
895
}
888
896
NewInfo.setVTYPE (MI.getOperand (2 ).getImm ());
889
897
@@ -956,6 +964,8 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
956
964
InstrInfo.setAVLImm (Imm);
957
965
} else {
958
966
InstrInfo.setAVLReg (VLOp.getReg ());
967
+ if (VLOp.getReg ().isVirtual ())
968
+ InstrInfo.setAVLDefMI (MRI->getVRegDef (VLOp.getReg ()));
959
969
}
960
970
} else {
961
971
assert (isScalarExtractInstr (MI));
@@ -976,10 +986,9 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
976
986
// register AVLs to avoid extending live ranges without being sure we can
977
987
// kill the original source reg entirely.
978
988
if (InstrInfo.hasAVLReg ()) {
979
- MachineInstr *DefMI = MRI->getUniqueVRegDef (InstrInfo.getAVLReg ());
980
- assert (DefMI);
989
+ const MachineInstr *DefMI = InstrInfo.getAVLDefMI ();
981
990
if (isVectorConfigInstr (*DefMI)) {
982
- VSETVLIInfo DefInstrInfo = getInfoForVSETVLI (*DefMI);
991
+ VSETVLIInfo DefInstrInfo = getInfoForVSETVLI (*DefMI, *MRI );
983
992
if (DefInstrInfo.hasSameVLMAX (InstrInfo) &&
984
993
(DefInstrInfo.hasAVLImm () || DefInstrInfo.hasAVLVLMAX ()))
985
994
InstrInfo.setAVL (DefInstrInfo);
@@ -1017,10 +1026,10 @@ void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
1017
1026
// it has the same VLMAX we want and the last VL/VTYPE we observed is the
1018
1027
// same, we can use the X0, X0 form.
1019
1028
if (Info.hasSameVLMAX (PrevInfo) && Info.hasAVLReg ()) {
1020
- MachineInstr *DefMI = MRI-> getUniqueVRegDef ( Info.getAVLReg () );
1029
+ const MachineInstr *DefMI = Info.getAVLDefMI ( );
1021
1030
assert (DefMI);
1022
1031
if (isVectorConfigInstr (*DefMI)) {
1023
- VSETVLIInfo DefInfo = getInfoForVSETVLI (*DefMI);
1032
+ VSETVLIInfo DefInfo = getInfoForVSETVLI (*DefMI, *MRI );
1024
1033
if (DefInfo.hasSameAVL (PrevInfo) && DefInfo.hasSameVLMAX (PrevInfo)) {
1025
1034
BuildMI (MBB, InsertPt, DL, TII->get (RISCV::PseudoVSETVLIX0))
1026
1035
.addReg (RISCV::X0, RegState::Define | RegState::Dead)
@@ -1138,8 +1147,8 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
1138
1147
if (Require.hasAVLReg () && CurInfo.hasCompatibleVTYPE (Used, Require)) {
1139
1148
MachineInstr *DefMI = MRI->getUniqueVRegDef (Require.getAVLReg ());
1140
1149
assert (DefMI);
1141
- if (isVectorConfigInstr (*DefMI )) {
1142
- VSETVLIInfo DefInfo = getInfoForVSETVLI (*DefMI );
1150
+ if (Require. getAVLDefMI () && isVectorConfigInstr (*Require. getAVLDefMI () )) {
1151
+ VSETVLIInfo DefInfo = getInfoForVSETVLI (*Require. getAVLDefMI (), *MRI );
1143
1152
if (DefInfo.hasSameAVL (CurInfo) && DefInfo.hasSameVLMAX (CurInfo))
1144
1153
return false ;
1145
1154
}
@@ -1225,13 +1234,15 @@ void RISCVInsertVSETVLI::transferBefore(VSETVLIInfo &Info,
1225
1234
void RISCVInsertVSETVLI::transferAfter (VSETVLIInfo &Info,
1226
1235
const MachineInstr &MI) const {
1227
1236
if (isVectorConfigInstr (MI)) {
1228
- Info = getInfoForVSETVLI (MI);
1237
+ Info = getInfoForVSETVLI (MI, *MRI );
1229
1238
return ;
1230
1239
}
1231
1240
1232
1241
if (RISCV::isFaultFirstLoad (MI)) {
1233
1242
// Update AVL to vl-output of the fault first load.
1234
1243
Info.setAVLReg (MI.getOperand (1 ).getReg ());
1244
+ if (MI.getOperand (1 ).getReg ().isVirtual ())
1245
+ Info.setAVLDefMI (MRI->getVRegDef (MI.getOperand (1 ).getReg ()));
1235
1246
return ;
1236
1247
}
1237
1248
@@ -1346,7 +1357,7 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require,
1346
1357
1347
1358
// We found a VSET(I)VLI make sure it matches the output of the
1348
1359
// predecessor block.
1349
- VSETVLIInfo DefInfo = getInfoForVSETVLI (*DefMI);
1360
+ VSETVLIInfo DefInfo = getInfoForVSETVLI (*DefMI, *MRI );
1350
1361
if (DefInfo != PBBExit)
1351
1362
return true ;
1352
1363
@@ -1500,7 +1511,7 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
1500
1511
// we need to prove the value is available at the point we're going
1501
1512
// to insert the vsetvli at.
1502
1513
if (AvailableInfo.hasAVLReg ()) {
1503
- MachineInstr *AVLDefMI = MRI-> getUniqueVRegDef ( AvailableInfo.getAVLReg () );
1514
+ const MachineInstr *AVLDefMI = AvailableInfo.getAVLDefMI ( );
1504
1515
assert (AVLDefMI);
1505
1516
// This is an inline dominance check which covers the case of
1506
1517
// UnavailablePred being the preheader of a loop.
@@ -1580,8 +1591,8 @@ static bool canMutatePriorConfig(const MachineInstr &PrevMI,
1580
1591
if (Used.VLZeroness ) {
1581
1592
if (isVLPreservingConfig (PrevMI))
1582
1593
return false ;
1583
- if (!getInfoForVSETVLI (PrevMI). hasEquallyZeroAVL ( getInfoForVSETVLI (MI),
1584
- MRI))
1594
+ if (!getInfoForVSETVLI (PrevMI, MRI)
1595
+ . hasEquallyZeroAVL ( getInfoForVSETVLI (MI, MRI), MRI))
1585
1596
return false ;
1586
1597
}
1587
1598
0 commit comments