diff options
| author | Guy David <guyda96@gmail.com> | 2025-08-06 21:05:48 +0300 |
|---|---|---|
| committer | Guy David <guyda96@gmail.com> | 2025-08-10 06:03:24 +0300 |
| commit | c9251a2ee0c2c7ebef1b44ee8337b6c892e5a83e (patch) | |
| tree | 55938e2face6b00817bdce7ab645d1c1f2f94416 /llvm/lib/CodeGen/MachineSink.cpp | |
| parent | cd834449a6d551cace6afad798ffad318f4ff325 (diff) | |
Diffstat (limited to 'llvm/lib/CodeGen/MachineSink.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/MachineSink.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp index 9ec5151a039b..d13f10729cae 100644 --- a/llvm/lib/CodeGen/MachineSink.cpp +++ b/llvm/lib/CodeGen/MachineSink.cpp @@ -835,6 +835,7 @@ bool MachineSinking::run(MachineFunction &MF) { RegClassInfo.runOnMachineFunction(MF); + SmallSet<MachineBasicBlock *, 8> NewBlocks; bool EverMadeChange = false; while (true) { @@ -854,6 +855,7 @@ bool MachineSinking::run(MachineFunction &MF) { auto NewSucc = Pair.first->SplitCriticalEdge( Pair.second, {LIS, SI, LV, MLI}, nullptr, &MDTU); if (NewSucc != nullptr) { + NewBlocks.insert(NewSucc); LLVM_DEBUG(dbgs() << " *** Splitting critical edge: " << printMBBReference(*Pair.first) << " -- " << printMBBReference(*NewSucc) << " -- " @@ -873,6 +875,28 @@ bool MachineSinking::run(MachineFunction &MF) { EverMadeChange = true; } + for (MachineBasicBlock *MBB : NewBlocks) { + if (MBB->isReturnBlock() || MBB->getSingleSuccessor()->isReturnBlock()) + continue; + // Only consider cheap instructions which don't touch physical registers. + if (all_of(llvm::make_range(MBB->begin(), MBB->getFirstTerminator()), + [this](const MachineInstr &MI) { + if (!MI.isAsCheapAsAMove()) + return false; + return all_of(MI.operands(), [this](const MachineOperand &MO) { + return !MO.isReg() || MO.getReg().isVirtual() || + TRI->isConstantPhysReg(MO.getReg()); + }); + })) { + assert(MBB->pred_size() == 1 && + "Block must have exactly one predecessor"); + assert(MBB->succ_size() == 1 && "Block must have exactly one successor"); + MachineBasicBlock *Pred = *MBB->pred_begin(); + Pred->splice(Pred->getFirstTerminator(), MBB, MBB->begin(), + MBB->getFirstTerminator()); + } + } + if (SinkInstsIntoCycle) { SmallVector<MachineCycle *, 8> Cycles(CI->toplevel_cycles()); SchedModel.init(STI); |
