Skip to content

Commit 4ca7c87

Browse files
committed
Keep VL = 1 check, check isCandidate after popping instead
1 parent a35e91e commit 4ca7c87

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,16 @@ bool RISCVVLOptimizer::isCandidate(const MachineInstr &MI) const {
11431143
if (MI.getNumDefs() != 1)
11441144
return false;
11451145

1146+
unsigned VLOpNum = RISCVII::getVLOpNum(Desc);
1147+
const MachineOperand &VLOp = MI.getOperand(VLOpNum);
1148+
1149+
// If the VL is 1, then there is no need to reduce it. This is an
1150+
// optimization, not needed to preserve correctness.
1151+
if (VLOp.isImm() && VLOp.getImm() == 1) {
1152+
LLVM_DEBUG(dbgs() << " Not a candidate because VL is already 1\n");
1153+
return false;
1154+
}
1155+
11461156
if (MI.mayRaiseFPException()) {
11471157
LLVM_DEBUG(dbgs() << "Not a candidate because may raise FP exception\n");
11481158
return false;
@@ -1335,8 +1345,6 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
13351345
continue;
13361346

13371347
MachineInstr *DefMI = MRI->getVRegDef(Op.getReg());
1338-
if (!isCandidate(*DefMI))
1339-
continue;
13401348

13411349
if (IgnoreSameBlock && DefMI->getParent() == MI.getParent())
13421350
continue;
@@ -1368,7 +1376,8 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
13681376
while (!Worklist.empty()) {
13691377
assert(MadeChange);
13701378
MachineInstr &MI = *Worklist.pop_back_val();
1371-
assert(isCandidate(MI));
1379+
if (!isCandidate(MI))
1380+
continue;
13721381
if (!tryReduceVL(MI))
13731382
continue;
13741383
PushOperands(MI, /*IgnoreSameBlock*/ false);

0 commit comments

Comments
 (0)