Skip to content

Commit 54b5107

Browse files
Slightly improve on the code
Signed-off-by: Mikhail R. Gadelha <[email protected]>
1 parent a703c3b commit 54b5107

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,21 +1513,17 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
15131513
/// this is geared to catch the common case of a fixed length vsetvl in a single
15141514
/// block loop when it could execute once in the preheader instead.
15151515
void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
1516-
// Only works for either one predecessor, or two predecessors if it's a loop
1517-
if (MBB.pred_empty() && MBB.pred_size() > 2)
1516+
// We need a prepredecessor to move the VSETVLI to
1517+
if (MBB.pred_empty())
15181518
return;
15191519

15201520
if (!BlockInfo[MBB.getNumber()].Pred.isUnknown())
15211521
return;
15221522

1523-
bool isLoop = false;
1524-
15251523
MachineBasicBlock *UnavailablePred = nullptr;
15261524
VSETVLIInfo AvailableInfo;
15271525
MachineBasicBlock *PreviousPred = nullptr;
15281526
for (MachineBasicBlock *P : MBB.predecessors()) {
1529-
isLoop |= (P == &MBB);
1530-
15311527
const VSETVLIInfo &PredInfo = BlockInfo[P->getNumber()].Exit;
15321528
if (PredInfo.isUnknown()) {
15331529
if (UnavailablePred)
@@ -1536,9 +1532,6 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
15361532
} else if (!AvailableInfo.isValid()) {
15371533
AvailableInfo = PredInfo;
15381534
} else if (AvailableInfo != PredInfo) {
1539-
if (!isLoop)
1540-
return;
1541-
15421535
DemandedFields PREDemands;
15431536
PREDemands.demandVTYPE();
15441537

@@ -1553,7 +1546,17 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
15531546
}
15541547
}
15551548

1556-
PreviousPred = P;
1549+
// Filter out loops
1550+
SmallVector<MachineBasicBlock *, 4> Preds = {MBB.predecessors().begin(),
1551+
MBB.predecessors().end()};
1552+
Preds.erase(std::remove_if(Preds.begin(), Preds.end(),
1553+
[&](MachineBasicBlock *P) { return P == &MBB; }),
1554+
Preds.end());
1555+
1556+
// Only works for one Pred for now
1557+
if (Preds.size() != 1)
1558+
return;
1559+
PreviousPred = *Preds.begin();
15571560
}
15581561

15591562
// Unreachable, single pred, or full redundancy. Note that FRE is handled by
@@ -1570,7 +1573,7 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
15701573
return;
15711574

15721575
// Critical edge - TODO: consider splitting?
1573-
if (UnavailablePred->succ_size() != 1 && !isLoop)
1576+
if (UnavailablePred->succ_size() != 1)
15741577
return;
15751578

15761579
// If the AVL value is a register (other than our VLMAX sentinel),

0 commit comments

Comments
 (0)