[PATCH] D109203: [X86] Don't clobber EBX in stackprobes

Elliot Saba via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 2 15:58:40 PDT 2021


staticfloat created this revision.
Herald added subscribers: pengfei, hiraditya.
staticfloat requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

On X86, the stackprobe emission code chooses the `R11D` register, which
is illegal on i686.  This ends up wrapping around to `EBX`, which does
not get properly callee-saved within the stack probing prologue,
clobbering the register for the callers.

We fix this by explicitly using `EAX` as the stack probe register.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109203

Files:
  llvm/lib/Target/X86/X86FrameLowering.cpp


Index: llvm/lib/Target/X86/X86FrameLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86FrameLowering.cpp
+++ llvm/lib/Target/X86/X86FrameLowering.cpp
@@ -652,7 +652,7 @@
   MF.insert(MBBIter, testMBB);
   MF.insert(MBBIter, tailMBB);
 
-  Register FinalStackProbed = Uses64BitFramePtr ? X86::R11 : X86::R11D;
+  Register FinalStackProbed = Uses64BitFramePtr ? X86::R11 : X86::EAX;
   BuildMI(MBB, MBBI, DL, TII.get(TargetOpcode::COPY), FinalStackProbed)
       .addReg(StackPtr)
       .setMIFlag(MachineInstr::FrameSetup);
@@ -1073,7 +1073,7 @@
       MF.insert(MBBIter, bodyMBB);
       MF.insert(MBBIter, footMBB);
       const unsigned MovMIOpc = Is64Bit ? X86::MOV64mi32 : X86::MOV32mi;
-      Register FinalStackProbed = Uses64BitFramePtr ? X86::R11 : X86::R11D;
+      Register FinalStackProbed = Uses64BitFramePtr ? X86::R11 : X86::EAX;
 
       // Setup entry block
       {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109203.370438.patch
Type: text/x-patch
Size: 940 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210902/373c0e97/attachment.bin>


More information about the llvm-commits mailing list