Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,10 @@ bool RISCVVLOptimizer::isCandidate(const MachineInstr &MI) const {
return false;
}

assert(MI.getOperand(0).isReg() &&
isVectorRegClass(MI.getOperand(0).getReg(), MRI) &&
"All supported instructions produce a vector register result");

LLVM_DEBUG(dbgs() << "Found a candidate for VL reduction: " << MI << "\n");
return true;
}
Expand Down Expand Up @@ -1295,9 +1299,6 @@ std::optional<MachineOperand> RISCVVLOptimizer::checkUsers(MachineInstr &MI) {
bool RISCVVLOptimizer::tryReduceVL(MachineInstr &MI) {
LLVM_DEBUG(dbgs() << "Trying to reduce VL for " << MI << "\n");

if (!isVectorRegClass(MI.getOperand(0).getReg(), MRI))
return false;

auto CommonVL = checkUsers(MI);
if (!CommonVL)
return false;
Expand Down Expand Up @@ -1347,14 +1348,11 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
auto PushOperands = [this, &Worklist](MachineInstr &MI,
bool IgnoreSameBlock) {
for (auto &Op : MI.operands()) {
if (!Op.isReg() || !Op.isUse() || !Op.getReg().isVirtual())
continue;

if (!isVectorRegClass(Op.getReg(), MRI))
if (!Op.isReg() || !Op.isUse() || !Op.getReg().isVirtual() ||
!isVectorRegClass(Op.getReg(), MRI))
continue;

MachineInstr *DefMI = MRI->getVRegDef(Op.getReg());

if (!isCandidate(*DefMI))
continue;

Expand Down Expand Up @@ -1388,6 +1386,7 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
while (!Worklist.empty()) {
assert(MadeChange);
MachineInstr &MI = *Worklist.pop_back_val();
assert(isCandidate(MI));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this assert redundant? isCandidate explicitly blocks insertion to the Worklist in PushOperands. That being said, isCandidate is cheap, so I don't have a strong objection.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can drop it if you want. Personally, I find it helpful to have the assertion at the point of extraction from a worklist. This is particular true when there's more than one insert point though - which doesn't apply here. Happy to defer to your preference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep it. It is cheap.

if (!tryReduceVL(MI))
continue;
PushOperands(MI, /*IgnoreSameBlock*/ false);
Expand Down
Loading