On Sun, Dec 8, 2024, 12:33 AM Jeff Law <jeffreya...@gmail.com> wrote:
> > > On 12/4/24 1:47 PM, H.J. Lu wrote: > > For targets, like x86, which define TARGET_PROMOTE_PROTOTYPES to return > > true, all integer arguments smaller than int are passed as int: > > > > [hjl@gnu-tgl-3 pr14907]$ cat x.c > > extern int baz (char c1); > > > > int > > foo (char c1) > > { > > return baz (c1); > > } > > [hjl@gnu-tgl-3 pr14907]$ gcc -S -O2 -m32 x.c > > [hjl@gnu-tgl-3 pr14907]$ cat x.s > > .file "x.c" > > .text > > .p2align 4 > > .globl foo > > .type foo, @function > > foo: > > .LFB0: > > .cfi_startproc > > movsbl 4(%esp), %eax > > movl %eax, 4(%esp) > > jmp baz > > .cfi_endproc > > .LFE0: > > .size foo, .-foo > > .ident "GCC: (GNU) 14.2.1 20240912 (Red Hat 14.2.1-3)" > > .section .note.GNU-stack,"",@progbits > > [hjl@gnu-tgl-3 pr14907]$ > > > > But integer promotion: > > > > movsbl 4(%esp), %eax > > movl %eax, 4(%esp) > > > > isn't necessary if incoming arguments and outgoing arguments are the > same. > > Use the incoming small integer argument type for the incoming argument if > > the incoming small integer argument is copied to the outgoing argument > > without any modification. > > > > gcc/ > > > > PR middle-end/14907 > > * calls.cc: (get_small_int_arg_type): New function. > > (initialize_argument_information): Call get_small_int_arg_type to > > get the small integer argument type. > Wouldn't this break a target where sub-integer arguments are passed > as-is? Do we have any such targets? > What my patch does is that if the incoming argument can be used as the outgoinging argument, don't promote the outgoing argument. Callee will see the same incoming argument as caller. This won't break anything since callee will see the same incoming argument when callee is called by caller's caller. > For targets that do promote, how is this different than PROMOTE_MODE? > What about targets where signedness of the type matters (Alpha > accoriding to the PROMOTE_MODE documentation). > PROMOTE_CODE is defined according to ABI and it is performed after PROMOTE_PROTOTYPES which is optional. My change has the same impact as a local small integer variable which is used for the outgoing argument. > Jeff > > > > H.J.