[llvm] [MCP] Move dependencies if they block copy propagation (PR #105562)
Gábor Spaits via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 22 13:04:08 PDT 2024
================
@@ -1033,23 +1229,39 @@ void MachineCopyPropagation::propagateDefs(MachineInstr &MI) {
LLVM_DEBUG(dbgs() << "MCP: Replacing " << printReg(MODef.getReg(), TRI)
<< "\n with " << printReg(Def, TRI) << "\n in "
<< MI << " from " << *Copy);
+ if (!MoveDependenciesForBetterCopyPropagation) {
+ MODef.setReg(Def);
+ MODef.setIsRenamable(CopyOperands->Destination->isRenamable());
- MODef.setReg(Def);
- MODef.setIsRenamable(CopyOperands->Destination->isRenamable());
-
- LLVM_DEBUG(dbgs() << "MCP: After replacement: " << MI << "\n");
- MaybeDeadCopies.insert(Copy);
- Changed = true;
- ++NumCopyBackwardPropagated;
+ LLVM_DEBUG(dbgs() << "MCP: After replacement: " << MI << "\n");
+ MaybeDeadCopies.insert(Copy);
+ Changed = true;
+ ++NumCopyBackwardPropagated;
+ } else if (InstructionsToMove) {
+ for (auto *I : *InstructionsToMove) {
+ MI.getParent()->splice(MI.getIterator(), MI.getParent(), I->getIterator());
+ }
+ }
}
}
void MachineCopyPropagation::BackwardCopyPropagateBlock(
- MachineBasicBlock &MBB) {
+ MachineBasicBlock &MBB, bool MoveDependenciesForBetterCopyPropagation) {
+ ScheduleDAGMCP DG{*(MBB.getParent()), nullptr, false};
----------------
spaits wrote:
I think the `ScheduleDAG` can only operate on basic blocks, it can not handle branching.
in the next line we have:
```cpp
DG.enterRegion(&MBB, MBB.begin(), MBB.end(), MBB.size());
```
In this call the following members of the `ScheduleDAG` are set:
```cpp
RegionBegin = begin;
RegionEnd = end;
```
and then in the `buildSchedGraph` call the main loop goes from `RegionEnd` to `RegionBegin`:
```cpp
for (MachineBasicBlock::iterator MII = RegionEnd, MIE = RegionBegin;
MII != MIE; --MII)
```
So for this reason I think there is a separate `ScheduleDAG` for each MBB. (Basically the MBB is the scheduling region here).
I may be wrong here. What do you think?
https://github.com/llvm/llvm-project/pull/105562
More information about the llvm-commits
mailing list