[llvm] [CodeGen] Don't schedule across frame register save/restore for sanitized functions (PR #221714)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 10:57:21 PDT 2026


================
@@ -1711,6 +1711,21 @@ bool TargetInstrInfo::isSchedulingBoundary(const MachineInstr &MI,
   if (MI.getOpcode() == TargetOpcode::INLINEASM_BR)
     return true;
 
+  // Sanitizers need a correct stack frame at the point of a crash,
+  // which can happen anywhere. Treat frame register modifications
+  // as scheduling boundaries so the scheduler can't reorder other
+  // instructions across the frame register save/restore.
+  if (MF.getFunction().hasFnAttribute(Attribute::SanitizeAddress) ||
+      MF.getFunction().hasFnAttribute(Attribute::SanitizeThread) ||
+      MF.getFunction().hasFnAttribute(Attribute::SanitizeMemory) ||
+      MF.getFunction().hasFnAttribute(Attribute::SanitizeType) ||
+      MF.getFunction().hasFnAttribute(Attribute::SanitizeHWAddress) ||
+      MF.getFunction().hasFnAttribute(Attribute::SanitizeMemTag)) {
+    Register FrameReg = TRI.getFrameRegister(MF);
----------------
arsenm wrote:

getFrameRegister also usually calls hasFP, so it will be obnoxiously slow to call in something as frequently needed as isSchedulingBoundary

https://github.com/llvm/llvm-project/pull/221714


More information about the llvm-commits mailing list