[llvm] [X86] Don't clobber x87 return values when zeroing call-used registers (PR #211129)

Phoebe Wang via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 18:51:02 PDT 2026


================
@@ -619,12 +619,23 @@ void X86FrameLowering::emitZeroCallUsedRegs(BitVector RegsToZero,
 
   // Zero out FP stack if referenced. Do this outside of the loop below so that
   // it's done only once.
-  const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
   for (MCRegister Reg : RegsToZero.set_bits()) {
     if (!X86::RFP80RegClass.contains(Reg))
       continue;
 
-    unsigned NumFPRegs = ST.is64Bit() ? 8 : 7;
+    // Don't push zeros over return values live in ST registers (implicit
+    // uses on the return): overflowing the 8-slot x87 stack replaces them
+    // with an indefinite NaN.
+    unsigned NumLiveSTRegs = 0;
+    for (const MachineInstr &MI : MBB.terminators())
+      if (MI.isReturn())
----------------
phoebewang wrote:

Return block only has one terminator and must be return. So No need the check here.

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


More information about the llvm-commits mailing list