@@ -1189,6 +1189,10 @@ bool RISCVVLOptimizer::isCandidate(const MachineInstr &MI) const {
11891189 return false ;
11901190 }
11911191
1192+ assert (MI.getOperand (0 ).isReg () &&
1193+ isVectorRegClass (MI.getOperand (0 ).getReg (), MRI) &&
1194+ " All supported instructions produce a vector register result" );
1195+
11921196 LLVM_DEBUG (dbgs () << " Found a candidate for VL reduction: " << MI << " \n " );
11931197 return true ;
11941198}
@@ -1295,9 +1299,6 @@ std::optional<MachineOperand> RISCVVLOptimizer::checkUsers(MachineInstr &MI) {
12951299bool RISCVVLOptimizer::tryReduceVL (MachineInstr &MI) {
12961300 LLVM_DEBUG (dbgs () << " Trying to reduce VL for " << MI << " \n " );
12971301
1298- if (!isVectorRegClass (MI.getOperand (0 ).getReg (), MRI))
1299- return false ;
1300-
13011302 auto CommonVL = checkUsers (MI);
13021303 if (!CommonVL)
13031304 return false ;
@@ -1347,14 +1348,11 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
13471348 auto PushOperands = [this , &Worklist](MachineInstr &MI,
13481349 bool IgnoreSameBlock) {
13491350 for (auto &Op : MI.operands ()) {
1350- if (!Op.isReg () || !Op.isUse () || !Op.getReg ().isVirtual ())
1351- continue ;
1352-
1353- if (!isVectorRegClass (Op.getReg (), MRI))
1351+ if (!Op.isReg () || !Op.isUse () || !Op.getReg ().isVirtual () ||
1352+ !isVectorRegClass (Op.getReg (), MRI))
13541353 continue ;
13551354
13561355 MachineInstr *DefMI = MRI->getVRegDef (Op.getReg ());
1357-
13581356 if (!isCandidate (*DefMI))
13591357 continue ;
13601358
@@ -1388,6 +1386,7 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
13881386 while (!Worklist.empty ()) {
13891387 assert (MadeChange);
13901388 MachineInstr &MI = *Worklist.pop_back_val ();
1389+ assert (isCandidate (MI));
13911390 if (!tryReduceVL (MI))
13921391 continue ;
13931392 PushOperands (MI, /* IgnoreSameBlock*/ false );
0 commit comments