@@ -404,7 +404,9 @@ DemandedFields getDemanded(const MachineInstr &MI, const RISCVSubtarget *ST) {
404
404
if (RISCVII::hasSEWOp (TSFlags)) {
405
405
Res.demandVTYPE ();
406
406
if (RISCVII::hasVLOp (TSFlags))
407
- Res.demandVL ();
407
+ if (const MachineOperand &VLOp = MI.getOperand (getVLOpNum (MI));
408
+ !VLOp.isReg () || !VLOp.isUndef ())
409
+ Res.demandVL ();
408
410
409
411
// Behavior is independent of mask policy.
410
412
if (!RISCVII::usesMaskPolicy (TSFlags))
@@ -524,7 +526,6 @@ class VSETVLIInfo {
524
526
AVLIsReg,
525
527
AVLIsImm,
526
528
AVLIsVLMAX,
527
- AVLIsIgnored,
528
529
Unknown,
529
530
} State = Uninitialized;
530
531
@@ -564,12 +565,9 @@ class VSETVLIInfo {
564
565
565
566
void setAVLVLMAX () { State = AVLIsVLMAX; }
566
567
567
- void setAVLIgnored () { State = AVLIsIgnored; }
568
-
569
568
bool hasAVLImm () const { return State == AVLIsImm; }
570
569
bool hasAVLReg () const { return State == AVLIsReg; }
571
570
bool hasAVLVLMAX () const { return State == AVLIsVLMAX; }
572
- bool hasAVLIgnored () const { return State == AVLIsIgnored; }
573
571
Register getAVLReg () const {
574
572
assert (hasAVLReg () && AVLRegDef.DefReg .isVirtual ());
575
573
return AVLRegDef.DefReg ;
@@ -600,8 +598,6 @@ class VSETVLIInfo {
600
598
setAVLRegDef (Info.getAVLVNInfo (), Info.getAVLReg ());
601
599
else if (Info.hasAVLVLMAX ())
602
600
setAVLVLMAX ();
603
- else if (Info.hasAVLIgnored ())
604
- setAVLIgnored ();
605
601
else {
606
602
assert (Info.hasAVLImm ());
607
603
setAVLImm (Info.getAVLImm ());
@@ -622,8 +618,6 @@ class VSETVLIInfo {
622
618
}
623
619
if (hasAVLVLMAX ())
624
620
return true ;
625
- if (hasAVLIgnored ())
626
- return false ;
627
621
return false ;
628
622
}
629
623
@@ -645,9 +639,6 @@ class VSETVLIInfo {
645
639
if (hasAVLVLMAX ())
646
640
return Other.hasAVLVLMAX () && hasSameVLMAX (Other);
647
641
648
- if (hasAVLIgnored ())
649
- return Other.hasAVLIgnored ();
650
-
651
642
return false ;
652
643
}
653
644
@@ -821,8 +812,6 @@ class VSETVLIInfo {
821
812
OS << " AVLImm=" << (unsigned )AVLImm;
822
813
if (hasAVLVLMAX ())
823
814
OS << " AVLVLMAX" ;
824
- if (hasAVLIgnored ())
825
- OS << " AVLIgnored" ;
826
815
OS << " , "
827
816
<< " VLMul=" << (unsigned )VLMul << " , "
828
817
<< " SEW=" << (unsigned )SEW << " , "
@@ -938,7 +927,8 @@ RISCVInsertVSETVLI::getInfoForVSETVLI(const MachineInstr &MI) const {
938
927
if (AVLReg == RISCV::X0)
939
928
NewInfo.setAVLVLMAX ();
940
929
else if (MI.getOperand (1 ).isUndef ())
941
- NewInfo.setAVLIgnored ();
930
+ // Otherwise use an AVL of 1 to avoid depending on previous vl.
931
+ NewInfo.setAVLImm (1 );
942
932
else {
943
933
VNInfo *VNI = getVNInfoFromReg (AVLReg, MI, LIS);
944
934
NewInfo.setAVLRegDef (VNI, AVLReg);
@@ -1014,17 +1004,17 @@ RISCVInsertVSETVLI::computeInfoForInstr(const MachineInstr &MI) const {
1014
1004
else
1015
1005
InstrInfo.setAVLImm (Imm);
1016
1006
} else if (VLOp.isUndef ()) {
1017
- InstrInfo.setAVLIgnored ();
1007
+ // Otherwise use an AVL of 1 to avoid depending on previous vl.
1008
+ InstrInfo.setAVLImm (1 );
1018
1009
} else {
1019
1010
VNInfo *VNI = getVNInfoFromReg (VLOp.getReg (), MI, LIS);
1020
1011
InstrInfo.setAVLRegDef (VNI, VLOp.getReg ());
1021
1012
}
1022
1013
} else {
1023
1014
assert (isScalarExtractInstr (MI));
1024
- // TODO: If we are more clever about x0,x0 insertion then we should be able
1025
- // to deduce that the VL is ignored based off of DemandedFields, and remove
1026
- // the AVLIsIgnored state. Then we can just use an arbitrary immediate AVL.
1027
- InstrInfo.setAVLIgnored ();
1015
+ // Pick a random value for state tracking purposes, will be ignored via
1016
+ // the demanded fields mechanism
1017
+ InstrInfo.setAVLImm (1 );
1028
1018
}
1029
1019
#ifndef NDEBUG
1030
1020
if (std::optional<unsigned > EEW = getEEWForLoadStore (MI)) {
@@ -1104,28 +1094,6 @@ void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
1104
1094
return ;
1105
1095
}
1106
1096
1107
- if (Info.hasAVLIgnored ()) {
1108
- // We can only use x0, x0 if there's no chance of the vtype change causing
1109
- // the previous vl to become invalid.
1110
- if (PrevInfo.isValid () && !PrevInfo.isUnknown () &&
1111
- Info.hasSameVLMAX (PrevInfo)) {
1112
- auto MI = BuildMI (MBB, InsertPt, DL, TII->get (RISCV::PseudoVSETVLIX0))
1113
- .addReg (RISCV::X0, RegState::Define | RegState::Dead)
1114
- .addReg (RISCV::X0, RegState::Kill)
1115
- .addImm (Info.encodeVTYPE ())
1116
- .addReg (RISCV::VL, RegState::Implicit);
1117
- LIS->InsertMachineInstrInMaps (*MI);
1118
- return ;
1119
- }
1120
- // Otherwise use an AVL of 1 to avoid depending on previous vl.
1121
- auto MI = BuildMI (MBB, InsertPt, DL, TII->get (RISCV::PseudoVSETIVLI))
1122
- .addReg (RISCV::X0, RegState::Define | RegState::Dead)
1123
- .addImm (1 )
1124
- .addImm (Info.encodeVTYPE ());
1125
- LIS->InsertMachineInstrInMaps (*MI);
1126
- return ;
1127
- }
1128
-
1129
1097
if (Info.hasAVLVLMAX ()) {
1130
1098
Register DestReg = MRI->createVirtualRegister (&RISCV::GPRRegClass);
1131
1099
auto MI = BuildMI (MBB, InsertPt, DL, TII->get (RISCV::PseudoVSETVLIX0))
@@ -1534,11 +1502,6 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
1534
1502
return ;
1535
1503
}
1536
1504
1537
- // If the AVL isn't used in its predecessors then bail, since we have no AVL
1538
- // to insert a vsetvli with.
1539
- if (AvailableInfo.hasAVLIgnored ())
1540
- return ;
1541
-
1542
1505
// Model the effect of changing the input state of the block MBB to
1543
1506
// AvailableInfo. We're looking for two issues here; one legality,
1544
1507
// one profitability.
0 commit comments