https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64895
Bug ID: 64895 Summary: [5 Regression] RA picks the wrong register for -fipa-ra Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: hjl.tools at gmail dot com CC: vmakarov at redhat dot com '-fipa-ra' Use caller save registers for allocation if those registers are not used by any called function. In that case it is not necessary to save and restore them around calls. This is only possible if called functions are part of same compilation unit as current function and they are compiled before it. But in this case testcase [hjl@gnu-tools-1 gcc]$ cat /tmp/x.c static int __attribute__((noinline)) bar (int x) { if (x > 4) return bar (x - 3); return 0; } int __attribute__((noinline)) foo (int y) { return y + bar (y); } [hjl@gnu-tools-1 gcc]$ ./xgcc -B./ -m32 -fpic -O2 -fipa-ra -fomit-frame-pointer -fno-optimize-sibling-calls -mregparm=1 /tmp/x.c -S -fno-asynchronous-unwind-tables [hjl@gnu-tools-1 gcc]$ cat x.s .file "x.c" .section .text.unlikely,"ax",@progbits .LCOLDB0: .text .LHOTB0: .p2align 4,,15 .type bar, @function bar: cmpl $4, %eax jg .L7 xorl %eax, %eax ret .p2align 4,,10 .p2align 3 .L7: subl $12, %esp subl $3, %eax call bar addl $12, %esp ret .size bar, .-bar .section .text.unlikely .LCOLDE0: .text .LHOTE0: .section .text.unlikely .LCOLDB1: .text .LHOTB1: .p2align 4,,15 .globl foo .type foo, @function foo: pushl %ebx movl %eax, %ebx subl $8, %esp call bar addl $8, %esp addl %ebx, %eax popl %ebx ret .size foo, .-foo .section .text.unlikely .LCOLDE1: .text .LHOTE1: .ident "GCC: (GNU) 5.0.0 20150201 (experimental)" .section .note.GNU-stack,"",@progbits [hjl@gnu-tools-1 gcc]$ Pick EBX instead of EDX to save EAX in foo.