This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, i386]: Use indirect functions some more
On Fri, Mar 18, 2011 at 10:08 PM, Richard Henderson <rth@redhat.com> wrote:
> On 03/18/2011 01:40 PM, Uros Bizjak wrote:
>> ? ? ? ?if (<X87MODEF:MODE>mode == SFmode)
>> - ? ? insn = gen_truncxfsf2 (operands[0], reg);
>> + ? ? insn = gen_truncxfsf2;
>> ? ? ? ?else if (<X87MODEF:MODE>mode == DFmode)
>> - ? ? insn = gen_truncxfdf2 (operands[0], reg);
>> + ? ? insn = gen_truncxfdf2;
>> ? ? ? ?else
>> ? ? ? gcc_unreachable ();
>
> Why is this a good thing? ?Surely the direct calls are much
> better predicted by the CPU...
I was hoping that cmove will be generated in this particular case for
64bit targets. I'm not aware of any other differences between direct
and indirect calls...
OTOH, call arguments do not need to be set-up twice when indirect call
is used. Please note that these are not CSE'd as shown by comparing
two examples below on 32bit i386:
--cut here--
#include <stdio.h>
#include <stdlib.h>
int foo (int, int);
int bar (int, int);
void test (int a, int b, int c)
{
int x;
if (c == 1)
x = foo (a, b);
else if (c == 2)
x = bar (a, b);
else
abort ();
printf ("%i\n", x);
}
void test_ (int a, int b, int c)
{
int (*x)(int, int);
if (c == 1)
x = foo;
else if (c == 2)
x = bar;
else
abort ();
printf ("%i\n", x (a, b));
}
--cut here--
test:
subl $28, %esp
movl 40(%esp), %eax
movl 32(%esp), %edx
movl 36(%esp), %ecx
cmpl $1, %eax
je .L6
cmpl $2, %eax
jne .L4
movl %ecx, 4(%esp)
movl %edx, (%esp)
call bar
.L3:
movl %eax, 36(%esp)
movl $.LC0, 32(%esp)
addl $28, %esp
jmp printf
.p2align 4,,7
.p2align 3
.L6:
movl %ecx, 4(%esp)
movl %edx, (%esp)
call foo
jmp .L3
.L4:
call abort
test_:
subl $28, %esp
movl 40(%esp), %eax
movl 32(%esp), %edx
movl 36(%esp), %ecx
cmpl $1, %eax
je .L9
cmpl $2, %eax
jne .L11
movl $bar, %eax
.L8:
movl %ecx, 4(%esp)
movl %edx, (%esp)
call *%eax
movl $.LC0, 32(%esp)
movl %eax, 36(%esp)
addl $28, %esp
jmp printf
.p2align 4,,7
.p2align 3
.L9:
.cfi_restore_state
movl $foo, %eax
jmp .L8
.L11:
call abort
> I can certainly understand sinking the call to emit_insn, as
> in the second hunk; that ought to save code size. ?Though the
> compiler really ought to be able to figure that out itself.
Currently, it does not.
Uros.