diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h index 2dcedfb40f3e6..7010cffe23a11 100644 --- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h +++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h @@ -436,7 +436,10 @@ class LLVM_ABI TargetInstrInfo : public MCInstrInfo { /// MachineSink determines on its own whether the instruction is safe to sink; /// this gives the target a hook to override the default behavior with regards /// to which instructions should be sunk. + /// + /// shouldPostRASink() is used by PostRAMachineSink. virtual bool shouldSink(const MachineInstr &MI) const { return true; } + virtual bool shouldPostRASink(const MachineInstr &MI) const { return true; } /// Return false if the instruction should not be hoisted by MachineLICM. /// diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp index cdcb29d92bfe6..94ed82eee9b8f 100644 --- a/llvm/lib/CodeGen/MachineSink.cpp +++ b/llvm/lib/CodeGen/MachineSink.cpp @@ -2287,6 +2287,10 @@ bool PostRAMachineSinkingImpl::tryToSinkCopy(MachineBasicBlock &CurBB, continue; } + // Don't postRASink instructions that the target prefers not to sink. + if (!TII->shouldPostRASink(MI)) + continue; + if (MI.isDebugOrPseudoInstr()) continue;