Skip to content

Commit 4b9faa4

Browse files
committed
[RISCV][VLOpt] Minor worklist invariant cleanup [NFC]
In retrospect, this probably should have been rolled into llvm#123973. It seemed more involved when I first decided to split. :)
1 parent 5895932 commit 4b9faa4

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
12951299
bool 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

Comments
 (0)