diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h --- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h +++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h @@ -1531,6 +1531,10 @@ const MachineInstr &DefMI, unsigned DefIdx) const; + /// Specify whether a target should hoist cheap instructions based on + /// register pressure. + virtual bool shouldHoistCheapInstructions() const { return false; } + /// Perform target-specific instruction verification. virtual bool verifyInstruction(const MachineInstr &MI, StringRef &ErrInfo) const { diff --git a/llvm/lib/CodeGen/MachineLICM.cpp b/llvm/lib/CodeGen/MachineLICM.cpp --- a/llvm/lib/CodeGen/MachineLICM.cpp +++ b/llvm/lib/CodeGen/MachineLICM.cpp @@ -1205,9 +1205,9 @@ unsigned Class = RPIdAndCost.first; int Limit = RegLimit[Class]; - // Don't hoist cheap instructions if they would increase register pressure, - // even if we're under the limit. - if (CheapInstr && !HoistCheapInsts) + // If target prefers not to hoist cheap instructions, don't hoist them, even + // if we're under the limit. + if (CheapInstr && !HoistCheapInsts && !TII->shouldHoistCheapInstructions()) return true; for (const auto &RP : BackTrace)