[PATCH] D143425: Reland "[X86][ABI] Don't preserve return regs for preserve_all/preserve_most CCs""

Anton Bikineev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 6 11:09:08 PST 2023


AntonBikineev created this revision.
AntonBikineev added a reviewer: pengfei.
Herald added subscribers: jdoerfert, hiraditya.
Herald added a project: All.
AntonBikineev requested review of this revision.
Herald added a project: LLVM.

The original change mistakenly excluded parameter registers from the
list of callee-saved-registers. This reland fixes it - it only excludes
the return registers for these calling conventions.

Phoebe, could you please take a look? This would be highly appreciated.

Original description:

> Currently both calling conventions preserve registers that are used to
> store a return value. This causes the returned value to be lost:
>
>   define i32 @bar() {
>     %1 = call preserve_mostcc i32 @foo()
>     ret i32 %1
>   }
>   
>   define preserve_mostcc i32 @foo() {
>     ret i32 2
>     ; preserve_mostcc will restore %rax,
>     ; whatever it was before the call.
>   }
>
> This contradicts the current documentation (preserve_allcc "behaves
> identical to the `C` calling conventions on how arguments and return
> values are passed") and also breaks [[clang::preserve_most]].
>
> This change makes CSRs be preserved iff they are not used to store a
> return value (e.g.  %rax for scalars, {%rax:%rdx} for __int128, %xmm0
> for double).  For void functions no additional registers are
> preserved, i.e.  the behaviour is backward compatible with existing
> code.




Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143425

Files:
  llvm/docs/LangRef.rst
  llvm/lib/Target/X86/X86CallingConv.td
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/preserve_allcc64-ret-double.ll
  llvm/test/CodeGen/X86/preserve_allcc64.ll
  llvm/test/CodeGen/X86/preserve_mostcc64-ret-double.ll
  llvm/test/CodeGen/X86/preserve_mostcc64.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143425.495217.patch
Type: text/x-patch
Size: 26283 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230206/84107cd1/attachment.bin>


More information about the llvm-commits mailing list