@@ -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 ;
@@ -1353,14 +1354,11 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
13531354 auto PushOperands = [this , &Worklist](MachineInstr &MI,
13541355 bool IgnoreSameBlock) {
13551356 for (auto &Op : MI.operands ()) {
1356- if (!Op.isReg () || !Op.isUse () || !Op.getReg ().isVirtual ())
1357- continue ;
1358-
1359- if (!isVectorRegClass (Op.getReg (), MRI))
1357+ if (!Op.isReg () || !Op.isUse () || !Op.getReg ().isVirtual () ||
1358+ !isVectorRegClass (Op.getReg (), MRI))
13601359 continue ;
13611360
13621361 MachineInstr *DefMI = MRI->getVRegDef (Op.getReg ());
1363-
13641362 if (!isCandidate (*DefMI))
13651363 continue ;
13661364
@@ -1394,6 +1392,7 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
13941392 while (!Worklist.empty ()) {
13951393 assert (MadeChange);
13961394 MachineInstr &MI = *Worklist.pop_back_val ();
1395+ assert (isCandidate (MI));
13971396 if (!tryReduceVL (MI))
13981397 continue ;
13991398 PushOperands (MI, /* IgnoreSameBlock*/ false );
0 commit comments