[PATCH] D61892: [AArch64] Treat x18 as callee-saved in functions with windows calling convention on non-windows OSes

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 29 07:01:50 PDT 2020


mstorsjo marked 2 inline comments as done.
mstorsjo added inline comments.


================
Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:2447
+    SavedRegs.set(AArch64::X18);
+  }
+
----------------
efriedma wrote:
> This change shouldn't be necessary. If some code in the function modifies x18, or calls some non-Win64 function, x18 will be clobbered.  Frame lowering should see that, and figure out it needs to save x18 without any extra help.
No, this is actually the core of the intent of this change.

When windows code (which expects x18 to be unmodified) calls an entry point in wine (marked with the windows calling convention), the entry point function (linux code but with a windows calling convention) itself probably won't clobber x18 (it's potentially even compiled with `-ffixed-x18` to avoid doing that) - but this function can call other functions (glibc, other userland libraries), and these functions can freely clobber x18.

So this is meant to always restore x18 on return from a windows calling convention function, as we can't really know what happened meanwhile.


================
Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:3947
+  // from those functions.
+  if (CallerCC == CallingConv::Win64 && !Subtarget->isTargetWindows())
+    return false;
----------------
efriedma wrote:
> Do we want to also check that the callee CC isn't Win64?
Hmm, indeed - in that case we could actually allow the tail call, yes. I'll see if I can add a test for that case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61892/new/

https://reviews.llvm.org/D61892





More information about the llvm-commits mailing list