https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81035
Bug ID: 81035
Summary: noreturn leads to worse code due to lack of sibcall
optimization
Product: gcc
Version: 6.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: fw at gcc dot gnu.org
Target Milestone: ---
Target: x86-64
Created attachment 41521
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41521&action=edit
C test case
The attached test case compiles to this code with -O2 -DNORETURN:
0000000000000000 <g>:
0: 69 d6 46 54 bc 00 imul $0xbc5446,%esi,%edx
6: 89 f0 mov %esi,%eax
8: 89 f9 mov %edi,%ecx
a: 0f af c7 imul %edi,%eax
d: 29 f1 sub %esi,%ecx
f: 48 83 ec 08 sub $0x8,%rsp
13: 01 fa add %edi,%edx
15: 01 c2 add %eax,%edx
17: 89 f0 mov %esi,%eax
19: 31 f8 xor %edi,%eax
1b: 69 ff a0 a2 14 00 imul $0x14a2a0,%edi,%edi
21: 0f af c1 imul %ecx,%eax
24: 01 f7 add %esi,%edi
26: 89 d6 mov %edx,%esi
28: 01 c7 add %eax,%edi
2a: e8 00 00 00 00 callq 2f <g+0x2f>
2b: R_X86_64_PC32 f-0x4
And with -O2:
0000000000000000 <g>:
0: 69 d6 46 54 bc 00 imul $0xbc5446,%esi,%edx
6: 89 f0 mov %esi,%eax
8: 89 f9 mov %edi,%ecx
a: 0f af c7 imul %edi,%eax
d: 29 f1 sub %esi,%ecx
f: 01 fa add %edi,%edx
11: 01 c2 add %eax,%edx
13: 89 f0 mov %esi,%eax
15: 31 f8 xor %edi,%eax
17: 69 ff a0 a2 14 00 imul $0x14a2a0,%edi,%edi
1d: 0f af c1 imul %ecx,%eax
20: 01 f7 add %esi,%edi
22: 89 d6 mov %edx,%esi
24: 01 c7 add %eax,%edi
26: e9 00 00 00 00 jmpq 2b <g+0x2b>
27: R_X86_64_PC32 f-0x4
The -O2 code is shorter because it doesn't need CFI annotations.
It's probably a good idea to inhibit the sibcall optimization for noreturn
functions, to get more accurate stack trace, but that's not what the manual
suggests.