Skip to content

Commit ce36480

Browse files
authored
[RISCV] Update V0Defs after moving Src in peepholes (#107359)
If we move a pseudo in tryReduceVL or foldVMV_V_V via ensureDominates, its V0 definition may have changed so we need to update V0Defs. This shouldn't have any functional change today since any pseudo which uses V0 won't be able to move past a new definition. However this will matter if we add a peephole to convert unmasked pseudos to masked pseudos and add a use of V0.
1 parent 62e6c1e commit ce36480

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class RISCVVectorPeephole : public MachineFunctionPass {
6161
}
6262

6363
private:
64-
bool tryToReduceVL(MachineInstr &MI) const;
64+
bool tryToReduceVL(MachineInstr &MI);
6565
bool convertToVLMAX(MachineInstr &MI) const;
6666
bool convertToWholeRegister(MachineInstr &MI) const;
6767
bool convertToUnmasked(MachineInstr &MI) const;
@@ -72,7 +72,7 @@ class RISCVVectorPeephole : public MachineFunctionPass {
7272
bool hasSameEEW(const MachineInstr &User, const MachineInstr &Src) const;
7373
bool isAllOnesMask(const MachineInstr *MaskDef) const;
7474
std::optional<unsigned> getConstant(const MachineOperand &VL) const;
75-
bool ensureDominates(const MachineOperand &Use, MachineInstr &Src) const;
75+
bool ensureDominates(const MachineOperand &Use, MachineInstr &Src);
7676

7777
/// Maps uses of V0 to the corresponding def of V0.
7878
DenseMap<const MachineInstr *, const MachineInstr *> V0Defs;
@@ -115,7 +115,7 @@ bool RISCVVectorPeephole::hasSameEEW(const MachineInstr &User,
115115
// Attempt to reduce the VL of an instruction whose sole use is feeding a
116116
// instruction with a narrower VL. This currently works backwards from the
117117
// user instruction (which might have a smaller VL).
118-
bool RISCVVectorPeephole::tryToReduceVL(MachineInstr &MI) const {
118+
bool RISCVVectorPeephole::tryToReduceVL(MachineInstr &MI) {
119119
// Note that the goal here is a bit multifaceted.
120120
// 1) For store's reducing the VL of the value being stored may help to
121121
// reduce VL toggles. This is somewhat of an artifact of the fact we
@@ -465,17 +465,18 @@ static bool dominates(MachineBasicBlock::const_iterator A,
465465
/// does. Returns false if doesn't dominate and we can't move. \p MO must be in
466466
/// the same basic block as \Src.
467467
bool RISCVVectorPeephole::ensureDominates(const MachineOperand &MO,
468-
MachineInstr &Src) const {
468+
MachineInstr &Src) {
469469
assert(MO.getParent()->getParent() == Src.getParent());
470470
if (!MO.isReg() || MO.getReg() == RISCV::NoRegister)
471471
return true;
472472

473473
MachineInstr *Def = MRI->getVRegDef(MO.getReg());
474474
if (Def->getParent() == Src.getParent() && !dominates(Def, Src)) {
475-
if (!isSafeToMove(Src, *Def->getNextNode()))
475+
MachineInstr *AfterDef = Def->getNextNode();
476+
if (!isSafeToMove(Src, *AfterDef))
476477
return false;
477-
// FIXME: Update V0Defs
478-
Src.moveBefore(Def->getNextNode());
478+
V0Defs[&Src] = V0Defs[AfterDef];
479+
Src.moveBefore(AfterDef);
479480
}
480481

481482
return true;

0 commit comments

Comments
 (0)