On Tue, Nov 5, 2024 at 8:07 AM Jeff Law <jeffreya...@gmail.com> wrote:
>
>
>
> On 11/1/24 4:32 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 unpromoted incoming integer arguments as outgoing arguments
> > if incoming integer arguments are the same as outgoing arguments to
> > avoid unnecessary integer promotion.
> Is there a particular reason x86 can't use the same mechanisms that

Other targets define TARGET_PROMOTE_PROTOTYPES to return false
to avoid this issue.   Changing x86 TARGET_PROMOTE_PROTOTYPES
to return false will break LLVM which assumes that incoming char/short
arguments on x86 are always extended to int.   The following targets

arc/arc.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
cris/cris.h:   defining TARGET_PROMOTE_PROTOTYPES that always returns true would
epiphany/epiphany.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
fr30/fr30.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
ft32/ft32.cc:#define TARGET_PROMOTE_PROTOTYPES       hook_bool_const_tree_true
i386/i386.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
ia64/ia64.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
iq2000/iq2000.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
lm32/lm32.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
m32r/m32r.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
m68k/m68k.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
mcore/mcore.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
mn10300/mn10300.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
moxie/moxie.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
nios2/nios2.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
pa/pa.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
stormy16/stormy16.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
v850/v850.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
vax/vax.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
xtensa/xtensa.cc:#define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true

suffer the same issue as x86.

> other targets used to expose how arguments are promoted and ultimately
> optimize away unnecessary promotions?
>
> jeff



-- 
H.J.

Reply via email to