[PATCH] D110869: [X86] Implement -fzero-call-used-regs option

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 4 01:14:42 PST 2022


craig.topper added a comment.

In D110869#3296031 <https://reviews.llvm.org/D110869#3296031>, @void wrote:

> In D110869#3295912 <https://reviews.llvm.org/D110869#3295912>, @craig.topper wrote:
>
>> In D110869#3295906 <https://reviews.llvm.org/D110869#3295906>, @void wrote:
>>
>>> In D110869#3295578 <https://reviews.llvm.org/D110869#3295578>, @nickdesaulniers wrote:
>>>
>>>> In D110869#3295559 <https://reviews.llvm.org/D110869#3295559>, @void wrote:
>>>>
>>>>> Weird. We generate similar code to GCC:
>>>>>
>>>>>   Clang:
>>>>>   _paravirt_ident_64:                     # @_paravirt_ident_64
>>>>>           movq    %rdi, %rax
>>>>>           xorq    %rdi, %rdi
>>>>>           retq
>>>>>   
>>>>>   GCC:
>>>>>   _paravirt_ident_64:
>>>>>           movq    %rdi, %rax      # tmp85, x
>>>>>           xorl    %edi, %edi      #
>>>>>           ret
>>>>
>>>> Does `xorl` not zero the upper 32b?
>>>
>>> I'm thinking no. But it's odd, because both are using `%rdi` but GCC is only zeroing out the bottom 32-bits. Seems a bit counter-intuitive.
>>
>> Every write to a 32-bit register on x86-64 zeros bits 63:32 of the register. `xorl %edi, %edi` has the same behavior as `xorq %rdi, %rdi`, but is 1 byte shorter to encode.
>
> Oh, interesting! TIL. So it's really not profitable to use `xorq` at all here...Though it does beg the question of why `xorq` exists. :-)

xorq is still useful when the registers are different.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110869



More information about the llvm-commits mailing list