@@ -172,7 +172,7 @@ static bool hasUndefinedMergeOp(const MachineInstr &MI,
172
172
return true ;
173
173
174
174
// If the tied operand is an IMPLICIT_DEF (or a REG_SEQUENCE whose operands
175
- // are solely IMPLICIT_DEFS), the pass through lanes are undefined.
175
+ // are solely IMPLICIT_DEFS), the pass through lanes are undefined.
176
176
const MachineOperand &UseMO = MI.getOperand (UseOpIdx);
177
177
if (MachineInstr *UseMI = MRI.getVRegDef (UseMO.getReg ())) {
178
178
if (UseMI->isImplicitDef ())
@@ -755,6 +755,10 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
755
755
void doLocalPostpass (MachineBasicBlock &MBB);
756
756
void doPRE (MachineBasicBlock &MBB);
757
757
void insertReadVL (MachineBasicBlock &MBB);
758
+ void emulateXTHeadVectorVSETIVLI (MachineBasicBlock &MBB,
759
+ MachineBasicBlock::iterator &InsertPt,
760
+ const DebugLoc &DL, const VSETVLIInfo &Info,
761
+ uint64_t UImm);
758
762
};
759
763
760
764
} // end anonymous namespace
@@ -916,11 +920,14 @@ void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
916
920
}
917
921
918
922
if (Info.hasAVLImm ()) {
919
- assert (!HasVendorXTHeadV && " XTHeadV extension does not support AVLImm" );
920
- BuildMI (MBB, InsertPt, DL, TII->get (RISCV::PseudoVSETIVLI))
921
- .addReg (RISCV::X0, RegState::Define | RegState::Dead)
922
- .addImm (Info.getAVLImm ())
923
- .addImm (Info.encodeVTYPE ());
923
+ if (HasVendorXTHeadV) {
924
+ emulateXTHeadVectorVSETIVLI (MBB, InsertPt, DL, Info, Info.getAVLImm ());
925
+ } else {
926
+ BuildMI (MBB, InsertPt, DL, TII->get (RISCV::PseudoVSETIVLI))
927
+ .addReg (RISCV::X0, RegState::Define | RegState::Dead)
928
+ .addImm (Info.getAVLImm ())
929
+ .addImm (Info.encodeVTYPE ());
930
+ }
924
931
return ;
925
932
}
926
933
@@ -943,15 +950,7 @@ void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
943
950
}
944
951
// Otherwise use an AVL of 0 to avoid depending on previous vl.
945
952
if (HasVendorXTHeadV) {
946
- // Generate the equivalent of `vsetivli rd, uimm, vtypei` in RVV 0.7
947
- auto UImmR = MRI->createVirtualRegister (&RISCV::GPRRegClass);
948
- BuildMI (MBB, InsertPt, DL, TII->get (RISCV::PseudoLI))
949
- .addReg (UImmR, RegState::Define)
950
- .addImm (0 );
951
- BuildMI (MBB, InsertPt, DL, TII->get (RISCV::PseudoTH_VSETVLI))
952
- .addReg (RISCV::X0, RegState::Define | RegState::Dead)
953
- .addReg (UImmR, RegState::Kill)
954
- .addImm (Info.encodeXTHeadVTYPE ());
953
+ emulateXTHeadVectorVSETIVLI (MBB, InsertPt, DL, Info, 0 );
955
954
} else {
956
955
BuildMI (MBB, InsertPt, DL, TII->get (RISCV::PseudoVSETIVLI))
957
956
.addReg (RISCV::X0, RegState::Define | RegState::Dead)
@@ -980,6 +979,30 @@ void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
980
979
.addImm (TypeI);
981
980
}
982
981
982
+ void RISCVInsertVSETVLI::emulateXTHeadVectorVSETIVLI (
983
+ MachineBasicBlock &MBB, MachineBasicBlock::iterator &InsertPt,
984
+ const DebugLoc &DL, const VSETVLIInfo &Info, uint64_t UImm) {
985
+ // RVV 1.0:
986
+ // vsetvli rd, rs1, vtypei # rd = new vl, rs1 = AVL, vtypei = vtype
987
+ // vsetivli rd, uimm, vtypei # rd = new vl, uimm = AVL, vtypei = vtype
988
+
989
+ // XTHeadVector:
990
+ // vsetvli rd, rs1, vtypei # rd = new vl, rs1 = AVL, vtypei = new vtype
991
+
992
+ // Let's load the AVLImm to a temporary register and use it as AVL in vsetvli
993
+ auto UImmR = MRI->createVirtualRegister (&RISCV::GPRRegClass);
994
+ // PseudoTH_VSETVLI requires the rs1 to be a GPRNoX0 register.
995
+ MRI->constrainRegClass (UImmR, &RISCV::GPRNoX0RegClass);
996
+
997
+ BuildMI (MBB, InsertPt, DL, TII->get (RISCV::PseudoLI))
998
+ .addReg (UImmR, RegState::Define)
999
+ .addImm (UImm);
1000
+ BuildMI (MBB, InsertPt, DL, TII->get (RISCV::PseudoTH_VSETVLI))
1001
+ .addReg (RISCV::X0, RegState::Define | RegState::Dead)
1002
+ .addReg (UImmR, RegState::Kill)
1003
+ .addImm (Info.encodeXTHeadVTYPE ());
1004
+ }
1005
+
983
1006
void RISCVInsertVSETVLI::insertVSETVLIForCOPY (MachineBasicBlock &MBB) {
984
1007
auto findRegSequence = [] (const MachineBasicBlock& BB,
985
1008
MachineBasicBlock::iterator I,
@@ -1709,7 +1732,7 @@ bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {
1709
1732
insertReadVL (MBB);
1710
1733
1711
1734
if (HasVendorXTHeadV)
1712
- for (MachineBasicBlock &MBB : MF)
1735
+ for (MachineBasicBlock &MBB : MF)
1713
1736
insertVSETVLIForCOPY (MBB);
1714
1737
1715
1738
BlockInfo.clear ();
0 commit comments