@@ -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 ;
@@ -1347,14 +1348,11 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
1347
1348
auto PushOperands = [this , &Worklist](MachineInstr &MI,
1348
1349
bool IgnoreSameBlock) {
1349
1350
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))
1354
1353
continue ;
1355
1354
1356
1355
MachineInstr *DefMI = MRI->getVRegDef (Op.getReg ());
1357
-
1358
1356
if (!isCandidate (*DefMI))
1359
1357
continue ;
1360
1358
@@ -1388,6 +1386,7 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
1388
1386
while (!Worklist.empty ()) {
1389
1387
assert (MadeChange);
1390
1388
MachineInstr &MI = *Worklist.pop_back_val ();
1389
+ assert (isCandidate (MI));
1391
1390
if (!tryReduceVL (MI))
1392
1391
continue ;
1393
1392
PushOperands (MI, /* IgnoreSameBlock*/ false );
0 commit comments