@@ -153,7 +153,7 @@ static std::optional<unsigned> getEEWForLoadStore(const MachineInstr &MI) {
153
153
}
154
154
}
155
155
156
- static bool isNonZeroLoadImmediate (MachineInstr &MI) {
156
+ static bool isNonZeroLoadImmediate (const MachineInstr &MI) {
157
157
return MI.getOpcode () == RISCV::ADDI &&
158
158
MI.getOperand (1 ).isReg () && MI.getOperand (2 ).isImm () &&
159
159
MI.getOperand (1 ).getReg () == RISCV::X0 &&
@@ -438,6 +438,8 @@ class VSETVLIInfo {
438
438
unsigned AVLImm;
439
439
};
440
440
441
+ const MachineInstr *AVLDefMI;
442
+
441
443
enum : uint8_t {
442
444
Uninitialized,
443
445
AVLIsReg,
@@ -454,7 +456,7 @@ class VSETVLIInfo {
454
456
455
457
public:
456
458
VSETVLIInfo ()
457
- : AVLImm(0 ), TailAgnostic(false ), MaskAgnostic(false ),
459
+ : AVLImm(0 ), AVLDefMI( nullptr ), TailAgnostic(false ), MaskAgnostic(false ),
458
460
SEWLMULRatioOnly (false ) {}
459
461
460
462
static VSETVLIInfo getUnknown () {
@@ -478,6 +480,8 @@ class VSETVLIInfo {
478
480
State = AVLIsImm;
479
481
}
480
482
483
+ void setAVLDefMI (const MachineInstr *DefMI) { AVLDefMI = DefMI; }
484
+
481
485
bool hasAVLImm () const { return State == AVLIsImm; }
482
486
bool hasAVLReg () const { return State == AVLIsReg; }
483
487
Register getAVLReg () const {
@@ -489,13 +493,16 @@ class VSETVLIInfo {
489
493
return AVLImm;
490
494
}
491
495
496
+ const MachineInstr *getAVLDefMI () const { return AVLDefMI; }
497
+
492
498
void setAVL (VSETVLIInfo Info) {
493
499
assert (Info.isValid ());
494
500
if (Info.isUnknown ())
495
501
setUnknown ();
496
- else if (Info.hasAVLReg ())
502
+ else if (Info.hasAVLReg ()) {
497
503
setAVLReg (Info.getAVLReg ());
498
- else {
504
+ setAVLDefMI (Info.getAVLDefMI ());
505
+ } else {
499
506
assert (Info.hasAVLImm ());
500
507
setAVLImm (Info.getAVLImm ());
501
508
}
@@ -512,8 +519,7 @@ class VSETVLIInfo {
512
519
if (hasAVLReg ()) {
513
520
if (getAVLReg () == RISCV::X0)
514
521
return true ;
515
- if (MachineInstr *MI = MRI.getVRegDef (getAVLReg ());
516
- MI && isNonZeroLoadImmediate (*MI))
522
+ if (getAVLDefMI () && isNonZeroLoadImmediate (*getAVLDefMI ()))
517
523
return true ;
518
524
return false ;
519
525
}
@@ -792,7 +798,8 @@ INITIALIZE_PASS(RISCVInsertVSETVLI, DEBUG_TYPE, RISCV_INSERT_VSETVLI_NAME,
792
798
793
799
// Return a VSETVLIInfo representing the changes made by this VSETVLI or
794
800
// VSETIVLI instruction.
795
- static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI) {
801
+ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
802
+ const MachineRegisterInfo &MRI) {
796
803
VSETVLIInfo NewInfo;
797
804
if (MI.getOpcode () == RISCV::PseudoVSETIVLI) {
798
805
NewInfo.setAVLImm (MI.getOperand (1 ).getImm ());
@@ -803,6 +810,8 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI) {
803
810
assert ((AVLReg != RISCV::X0 || MI.getOperand (0 ).getReg () != RISCV::X0) &&
804
811
" Can't handle X0, X0 vsetvli yet" );
805
812
NewInfo.setAVLReg (AVLReg);
813
+ if (AVLReg.isVirtual ())
814
+ NewInfo.setAVLDefMI (MRI.getVRegDef (AVLReg));
806
815
}
807
816
NewInfo.setVTYPE (MI.getOperand (2 ).getImm ());
808
817
@@ -875,6 +884,8 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
875
884
InstrInfo.setAVLImm (Imm);
876
885
} else {
877
886
InstrInfo.setAVLReg (VLOp.getReg ());
887
+ if (VLOp.getReg ().isVirtual ())
888
+ InstrInfo.setAVLDefMI (MRI->getVRegDef (VLOp.getReg ()));
878
889
}
879
890
} else {
880
891
assert (isScalarExtractInstr (MI));
@@ -892,9 +903,10 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
892
903
// register AVLs to avoid extending live ranges without being sure we can
893
904
// kill the original source reg entirely.
894
905
if (InstrInfo.hasAVLReg () && InstrInfo.getAVLReg ().isVirtual ()) {
895
- MachineInstr *DefMI = MRI->getVRegDef (InstrInfo.getAVLReg ());
896
- if (DefMI && isVectorConfigInstr (*DefMI)) {
897
- VSETVLIInfo DefInstrInfo = getInfoForVSETVLI (*DefMI);
906
+ if (InstrInfo.getAVLDefMI () &&
907
+ isVectorConfigInstr (*InstrInfo.getAVLDefMI ())) {
908
+ VSETVLIInfo DefInstrInfo =
909
+ getInfoForVSETVLI (*InstrInfo.getAVLDefMI (), *MRI);
898
910
if (DefInstrInfo.hasSameVLMAX (InstrInfo) &&
899
911
(DefInstrInfo.hasAVLImm () || DefInstrInfo.getAVLReg () == RISCV::X0)) {
900
912
InstrInfo.setAVL (DefInstrInfo);
@@ -934,9 +946,9 @@ void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
934
946
// same, we can use the X0, X0 form.
935
947
if (Info.hasSameVLMAX (PrevInfo) && Info.hasAVLReg () &&
936
948
Info.getAVLReg ().isVirtual ()) {
937
- if (MachineInstr *DefMI = MRI-> getVRegDef ( Info.getAVLReg () )) {
938
- if (isVectorConfigInstr (*DefMI )) {
939
- VSETVLIInfo DefInfo = getInfoForVSETVLI (*DefMI );
949
+ if (Info.getAVLDefMI ( )) {
950
+ if (isVectorConfigInstr (*Info. getAVLDefMI () )) {
951
+ VSETVLIInfo DefInfo = getInfoForVSETVLI (*Info. getAVLDefMI (), *MRI );
940
952
if (DefInfo.hasSameAVL (PrevInfo) && DefInfo.hasSameVLMAX (PrevInfo)) {
941
953
BuildMI (MBB, InsertPt, DL, TII->get (RISCV::PseudoVSETVLIX0))
942
954
.addReg (RISCV::X0, RegState::Define | RegState::Dead)
@@ -1056,9 +1068,9 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
1056
1068
// VSETVLI here.
1057
1069
if (Require.hasAVLReg () && Require.getAVLReg ().isVirtual () &&
1058
1070
CurInfo.hasCompatibleVTYPE (Used, Require)) {
1059
- if (MachineInstr *DefMI = MRI-> getVRegDef ( Require.getAVLReg () )) {
1060
- if (isVectorConfigInstr (*DefMI )) {
1061
- VSETVLIInfo DefInfo = getInfoForVSETVLI (*DefMI );
1071
+ if (Require.getAVLDefMI ( )) {
1072
+ if (isVectorConfigInstr (*Require. getAVLDefMI () )) {
1073
+ VSETVLIInfo DefInfo = getInfoForVSETVLI (*Require. getAVLDefMI (), *MRI );
1062
1074
if (DefInfo.hasSameAVL (CurInfo) && DefInfo.hasSameVLMAX (CurInfo))
1063
1075
return false ;
1064
1076
}
@@ -1145,13 +1157,15 @@ void RISCVInsertVSETVLI::transferBefore(VSETVLIInfo &Info,
1145
1157
void RISCVInsertVSETVLI::transferAfter (VSETVLIInfo &Info,
1146
1158
const MachineInstr &MI) const {
1147
1159
if (isVectorConfigInstr (MI)) {
1148
- Info = getInfoForVSETVLI (MI);
1160
+ Info = getInfoForVSETVLI (MI, *MRI );
1149
1161
return ;
1150
1162
}
1151
1163
1152
1164
if (RISCV::isFaultFirstLoad (MI)) {
1153
1165
// Update AVL to vl-output of the fault first load.
1154
1166
Info.setAVLReg (MI.getOperand (1 ).getReg ());
1167
+ if (MI.getOperand (1 ).getReg ().isVirtual ())
1168
+ Info.setAVLDefMI (MRI->getVRegDef (MI.getOperand (1 ).getReg ()));
1155
1169
return ;
1156
1170
}
1157
1171
@@ -1270,7 +1284,7 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require,
1270
1284
1271
1285
// We found a VSET(I)VLI make sure it matches the output of the
1272
1286
// predecessor block.
1273
- VSETVLIInfo DefInfo = getInfoForVSETVLI (*DefMI);
1287
+ VSETVLIInfo DefInfo = getInfoForVSETVLI (*DefMI, *MRI );
1274
1288
if (!DefInfo.hasSameAVL (PBBInfo.Exit ) ||
1275
1289
!DefInfo.hasSameVTYPE (PBBInfo.Exit ))
1276
1290
return true ;
@@ -1418,7 +1432,7 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
1418
1432
// we need to prove the value is available at the point we're going
1419
1433
// to insert the vsetvli at.
1420
1434
if (AvailableInfo.hasAVLReg () && RISCV::X0 != AvailableInfo.getAVLReg ()) {
1421
- MachineInstr *AVLDefMI = MRI-> getVRegDef ( AvailableInfo.getAVLReg () );
1435
+ const MachineInstr *AVLDefMI = AvailableInfo.getAVLDefMI ( );
1422
1436
if (!AVLDefMI)
1423
1437
return ;
1424
1438
// This is an inline dominance check which covers the case of
@@ -1504,8 +1518,8 @@ static bool canMutatePriorConfig(const MachineInstr &PrevMI,
1504
1518
if (Used.VLZeroness ) {
1505
1519
if (isVLPreservingConfig (PrevMI))
1506
1520
return false ;
1507
- if (!getInfoForVSETVLI (PrevMI). hasEquallyZeroAVL ( getInfoForVSETVLI (MI),
1508
- MRI))
1521
+ if (!getInfoForVSETVLI (PrevMI, MRI)
1522
+ . hasEquallyZeroAVL ( getInfoForVSETVLI (MI, MRI), MRI))
1509
1523
return false ;
1510
1524
}
1511
1525
0 commit comments