This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] X86-64: Add -mskip-rax-setup
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Uros Bizjak <ubizjak at gmail dot com>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Rasmus Villemoes <linux at rasmusvillemoes dot dk>, "x86 at kernel dot org" <x86 at kernel dot org>, Andi Kleen <andi at firstfloor dot org>, Ingo Molnar <mingo at redhat dot com>, "H. Peter Anvin" <hpa at zytor dot com>, Thomas Gleixner <tglx at linutronix dot de>
- Date: Thu, 18 Dec 2014 06:09:44 -0800
- Subject: Re: [PATCH] X86-64: Add -mskip-rax-setup
- Authentication-results: sourceware.org; auth=none
- References: <20141218131150 dot GA32638 at intel dot com> <CAFULd4ZaY5USX+CKdzoq1zWL8kZ3VqVx7KGxwb_tQEzbX03u-A at mail dot gmail dot com> <CAFULd4avYqhgA-D7+_w3b0Uk9jaso7JpXQXL2zU56Avs23i1og at mail dot gmail dot com> <CAFULd4asXmUnG+eYW9jyW7EQDLydTUnKUinW7yhRUo+cGauEVA at mail dot gmail dot com>
On Thu, Dec 18, 2014 at 6:03 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Thu, Dec 18, 2014 at 2:49 PM, Uros Bizjak <ubizjak@gmail.com> wrote:
>
>>>> The Linux kernel never passes floating point arguments around, vararg
>>>> functions or not. Hence no vector registers are ever used when calling a
>>>> vararg function. But gcc still dutifully emits an "xor %eax,%eax" before
>>>> each and every call of a vararg function. Since no callee use that for
>>>> anything, these instructions are redundant.
>>>>
>>>> This patch adds the -mskip-rax-setup option to skip setting up RAX
>>>> register when SSE is disabled and there are no variable arguments passed
>>>> in vector registers. Since RAX register is used to avoid unnecessarily
>>>> saving vector registers on stack when passing variable arguments, the
>>>> impacts of this option are callees may waste some stack space, misbehave
>>>> or jump to a random location. GCC 4.4 or newer don't those issues,
>>>> regardless the RAX register value since they don't check the RAX register
>>>> value when SSE is disabled, regardless the RAX register value:
>>>>
>>>> https://gcc.gnu.org/ml/gcc-patches/2008-09/msg00127.html
>>>>
>>>> I used it on kernel 3.17.7:
>>>>
>>>> text data bss dec hex filename
>>>> 11493571 2271232 5926912 19691715 12c78c3 vmlinux.skip-rax
>>>> 11517879 2271232 5926912 19716023 12cd7b7 vmlinux.orig
>>>>
>>>> It removed 14309 redundant "xor %eax,%eax" instructions and saved about
>>>> 27KB. I am currently running the new kernel without any problem. OK
>>>> for trunk?
>>>
>>> How about skipping RAX setup unconditionally for !TARGET_SSE? Please
>>> see ix86_conditional_register_usage, where SSE registers are squashed
>>> for !TARGET_SSE, so it is not possible to use them even in the inline
>>> asm.
>>
>> ... when -ffreestanding is in effect, of course.
>
> Ops, this is not the unconditional default kernel compile flag. It is
> defined only for 32bit builds, where:
>
> # temporary until string.h is fixed
> KBUILD_CFLAGS += -ffreestanding
>
> Yes, it looks to me that new option is the way to go.
Is this an OK?
Some really old gcc versions used an indirect jump based on the eax input
and they didn't zero extend first. So with those compilers, you could actually
jump to a random location. You can enable it only when you can compile
everything with a newer GCC.
Thanks.
--
H.J.