On Wed, May 14, 2025 at 2:12 PM Hongtao Liu <crazy...@gmail.com> wrote:
>
> On Fri, Apr 18, 2025 at 7:10 PM H.J. Lu <hjl.to...@gmail.com> wrote:
> >
> > Add preserve_none attribute which is similar to no_callee_saved_registers
> > attribute, except on x86-64, r12, r13, r14, r15, rdi and rsi registers are
> Could you split preserve_none into a separate patch,
> It looks like it's different from clang's preserve_none[1], can we
> make them align?
> [1] https://clang.llvm.org/docs/AttributeReference.html
>
> > used for integer parameter passing.  This can be used in an interpreter
> > to avoid saving/restoring the registers in functions which processing
> > byte codes.  It improved the pystones benchmark by 6-7%:
> >
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119628#c15
> >
> > Remove -mgeneral-regs-only restriction on no_caller_saved_registers
> > attribute.  Only SSE is allowed since SSE XMM register load preserves
> > the upper bits in YMM/ZMM register while YMM register load zeros the
> > upper 256 bits of ZMM register, and preserving 32 ZMM registers can
> > be quite expensive.
> >
> > gcc/
> >
> >         PR target/119628
> >         * config/i386/i386-expand.cc (ix86_expand_call): Call
> >         ix86_type_preserve_none_attribute_p instead of looking up
> >         no_callee_saved_registers attribute.
> >         * config/i386/i386-options.cc (ix86_set_func_type): Call
> >         ix86_type_preserve_none_attribute_p instead of looking up
> >         no_callee_saved_registers attribute.  Check preserve_none
> >         attribute for interrupt attribute.  Don't check
> >         no_caller_saved_registers and no_callee_saved_registers conflicts
> >         here.
> >         (ix86_set_current_function): Allow SSE with
> >         no_caller_saved_registers attribute.
> >         (ix86_handle_call_saved_registers_attribute): Check preserve_none,
> >         no_callee_saved_registers and no_caller_saved_registers conflicts.
> >         (ix86_gnu_attributes): Add preserve_none attribute.
> >         * config/i386/i386-protos.h (ix86_type_preserve_none_attribute_p):
> >         New.
> >         * config/i386/i386.cc
> >         (x86_64_preserve_none_int_parameter_registers): New.
> >         (ix86_using_red_zone): Don't use red-zone when there are no
> >         caller-saved registers with SSE.
> >         (ix86_type_preserve_none_attribute_p): New.
> >         (ix86_function_ok_for_sibcall): Call
> >         ix86_type_preserve_none_attribute_p instead of looking up
> >         no_callee_saved_registers attribute.
> >         (ix86_comp_type_attributes): Call
> >         ix86_type_preserve_none_attribute_p instead of looking up
> >         no_callee_saved_registers attribute.  Return 0 if preserve_none
> >         attribute doesn't match in 64-bit mode.
> >         (ix86_function_arg_regno_p): If preserve_none calling convention
> >         is used, use x86_64_preserve_none_int_parameter_registers.
> >         (ix86_call_abi_override): Also set the preserve_none_abi field.
> >         (init_cumulative_args): Likewise.
> >         (function_arg_64): Use x86_64_preserve_none_int_parameter_registers
> >         with preserve_none attribute.
> >         (setup_incoming_varargs_64): Use
> >         x86_64_preserve_none_int_parameter_registers with preserve_none
> >         attribute.
> >         (ix86_nsaved_sseregs): Allow saving XMM registers for
> >         no_caller_saved_registers attribute.
> >         (ix86_compute_frame_layout): Likewise.
> >         (x86_this_parameter): Use
> >         x86_64_preserve_none_int_parameter_registers with preserve_none
> >         attribute.
> >         * config/i386/i386.h (ix86_args): Add preserve_none_abi.
> >         (call_saved_registers_type): Update comments for
> >         TYPE_NO_CALLEE_SAVED_REGISTERS.
> >         (machine_function): Add preserve_none_abi.
> >         * doc/extend.texi: Add preserve_none attribute.  Update
> >         no_caller_saved_registers attribute to remove -mgeneral-regs-only
> >         restriction.
> >

...

> > diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
> > index 8507243d726..3b5c9520ddf 100644
> > --- a/gcc/config/i386/i386.h
> > +++ b/gcc/config/i386/i386.h
> > @@ -1682,6 +1682,8 @@ typedef struct ix86_args {
> >    int stdarg;                   /* Set to 1 if function is stdarg.  */
> >    enum calling_abi call_abi;   /* Set to SYSV_ABI for sysv abi. Otherwise
> >                                    MS_ABI for ms abi.  */
> > +  bool preserve_none_abi;      /* Set to true if the preserve_none ABI is
> > +                                  used.  */
> >    tree decl;                   /* Callee decl.  */
> >  } CUMULATIVE_ARGS;
> >
> > @@ -2782,7 +2784,7 @@ enum call_saved_registers_type
> >       or "no_caller_saved_registers" attribute.  */
> >    TYPE_NO_CALLER_SAVED_REGISTERS,
> >    /* The current function is a function specified with the
> > -     "no_callee_saved_registers" attribute.  */
> > +     "no_callee_saved_registers"/"preserve_none" attribute.  */
> >    TYPE_NO_CALLEE_SAVED_REGISTERS,
> Can we introduce a new member TYPE_PRESERVE_NONE instead of combining
> it with TYPE_NO_CALLEE_SAVED_REGISTERS.
> TYPE_PRESERVE_{MOST, ALL} can also be introduced if we want, and they
> should conflict with each other.(preserve_none should conflict
> no_callee_saved_registers)

Fixed in the v2 patch:

https://gcc.gnu.org/pipermail/gcc-patches/2025-May/684572.html

> >    /* The current function is a function specified with the "noreturn"
> >       attribute.  */
> > @@ -2816,6 +2818,9 @@ struct GTY(()) machine_function {
> >       to be used. MS_ABI means ms abi. Otherwise SYSV_ABI means sysv abi.  
> > */
> >    ENUM_BITFIELD(calling_abi) call_abi : 8;
> >
> > +  /* True if the preserve_none ABI is used.  */
> > +  BOOL_BITFIELD preserve_none_abi : 1;
> > +
> >    /* Nonzero if the function accesses a previous frame.  */
> >    BOOL_BITFIELD accesses_prev_frame : 1;
> >
> > diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
> > index 0978c4c41b2..4be531bb4fc 100644
> > --- a/gcc/doc/extend.texi
> > +++ b/gcc/doc/extend.texi
> > @@ -6117,6 +6117,13 @@ registers. For example, this attribute can be used 
> > for a function
> >  called from the interrupt handler assembly stub which will preserve
> >  all registers and return from interrupt.
> >
> > +@cindex @code{preserve_none} function attribute, x86
> > +@item preserve_none
> > +This attribute is similar to @code{no_callee_saved_registers}, except
> > +on x86-64, r12, r13, r14, r15, rdi and rsi registers are used for
> > +integer parameter passing and this calling convention is subject to
> > +change.
> > +
> >  @cindex @code{no_caller_saved_registers} function attribute, x86
> >  @item no_caller_saved_registers
> >  Use this attribute to indicate that the specified function has no
> > @@ -6124,9 +6131,10 @@ caller-saved registers. That is, all registers are 
> > callee-saved. For
> >  example, this attribute can be used for a function called from an
> >  interrupt handler. The compiler generates proper function entry and
> >  exit sequences to save and restore any modified registers, except for
> > -the EFLAGS register.  Since GCC doesn't preserve SSE, MMX nor x87
> > -states, the GCC option @option{-mgeneral-regs-only} should be used to
> > -compile functions with @code{no_caller_saved_registers} attribute.
> > +the EFLAGS register.  Since GCC doesn't preserve YMM nor ZMM registers,
> > +@code{no_caller_saved_registers} attribute can't be used on functions
> > +with AVX enabled.  Note that MMX and x87 registers aren't preserved by
> > +@code{no_caller_saved_registers} attribute.
> >
> >  @cindex @code{interrupt} function attribute, x86
> >  @item interrupt



-- 
H.J.

Reply via email to