@@ -1189,6 +1189,10 @@ bool RISCVVLOptimizer::isCandidate(const MachineInstr &MI) const {
1189
1189
return false ;
1190
1190
}
1191
1191
1192
+ assert (MI.getOperand (0 ).isReg () &&
1193
+ isVectorRegClass (MI.getOperand (0 ).getReg (), MRI) &&
1194
+ " All supported instructions produce a vector register result" );
1195
+
1192
1196
LLVM_DEBUG (dbgs () << " Found a candidate for VL reduction: " << MI << " \n " );
1193
1197
return true ;
1194
1198
}
@@ -1295,9 +1299,6 @@ std::optional<MachineOperand> RISCVVLOptimizer::checkUsers(MachineInstr &MI) {
1295
1299
bool RISCVVLOptimizer::tryReduceVL (MachineInstr &MI) {
1296
1300
LLVM_DEBUG (dbgs () << " Trying to reduce VL for " << MI << " \n " );
1297
1301
1298
- if (!isVectorRegClass (MI.getOperand (0 ).getReg (), MRI))
1299
- return false ;
1300
-
1301
1302
auto CommonVL = checkUsers (MI);
1302
1303
if (!CommonVL)
1303
1304
return false ;
@@ -1353,14 +1354,11 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
1353
1354
auto PushOperands = [this , &Worklist](MachineInstr &MI,
1354
1355
bool IgnoreSameBlock) {
1355
1356
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))
1360
1359
continue ;
1361
1360
1362
1361
MachineInstr *DefMI = MRI->getVRegDef (Op.getReg ());
1363
-
1364
1362
if (!isCandidate (*DefMI))
1365
1363
continue ;
1366
1364
@@ -1394,6 +1392,7 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
1394
1392
while (!Worklist.empty ()) {
1395
1393
assert (MadeChange);
1396
1394
MachineInstr &MI = *Worklist.pop_back_val ();
1395
+ assert (isCandidate (MI));
1397
1396
if (!tryReduceVL (MI))
1398
1397
continue ;
1399
1398
PushOperands (MI, /* IgnoreSameBlock*/ false );
0 commit comments