http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56165
Bug #: 56165 Summary: Missed optimization for 'noreturn' functions Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: akob...@mail.ru Target: x86_64-linux-gnu Created attachment 29318 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29318 Example source code 1) Functions with __attribute__((noreturn)) contain unnecessary push rbx or sub rsp,8 instructions in prologue. 2) Tail call need replace to jmp. Source code (there is 4 highlighted lines with !!!): ===Intrpt64.cpp=== struct _BiosConsole { virtual void __attribute__((stdcall)) PrintHexDWord(long n); }; void __attribute__((noreturn)) Intrpt_All(long* thr, long IntNum) { _BiosConsole BiosCons; BiosCons.PrintHexDWord((long)thr); asm volatile("mov rsp, %0;" : : "r" (thr)); for(;;){} } void __attribute__((noreturn)) Intrpt_0() { register long* thr; asm volatile("mov %0,rsp" : "=g" (thr)); Intrpt_All(thr, 0); } ===END=== Compile: x86_64-linux-gnu-gcc -c -Wall -Wno-attributes -save-temps -fverbose-asm -masm=intel -march=core2 -mcmodel=large -mno-mmx -mno-sse -O1 -fno-rtti -fno-default-inline -fomit-frame-pointer -falign-functions=16 -foptimize-sibling-calls -ffreestanding -fno-stack-protector --no-exceptions Intrpt64.cpp Generated Assembly code: ===Intrpt64.s=== .text .p2align 4,,15 .globl _Z10Intrpt_AllPll .type _Z10Intrpt_AllPll, @function _Z10Intrpt_AllPll: .LFB0: .cfi_startproc push rbx # TRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .cfi_def_cfa_offset 16 .cfi_offset 3, -16 sub rsp, 16 #, .cfi_def_cfa_offset 32 mov rbx, rdi # thr, thr movabs rax, OFFSET FLAT:_ZTV12_BiosConsole+16 #, mov QWORD PTR [rsp+8], rax # BiosCons._vptr._BiosConsole, mov rsi, rdi #, thr lea rdi, [rsp+8] #, movabs rax, OFFSET FLAT:_ZN12_BiosConsole13PrintHexDWordEl # tmp64, call rax # JMP !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #APP # 14 "Intrpt64.cpp" 1 mov rsp, rbx; # thr # 0 "" 2 #NO_APP .L2: jmp .L2 # .cfi_endproc .LFE0: .size _Z10Intrpt_AllPll, .-_Z10Intrpt_AllPll .p2align 4,,15 .globl _Z8Intrpt_0v .type _Z8Intrpt_0v, @function _Z8Intrpt_0v: .LFB4: .cfi_startproc sub rsp, 8 # TRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .cfi_def_cfa_offset 16 #APP # 21 "Intrpt64.cpp" 1 mov rdi,rsp # thr # 0 "" 2 #NO_APP mov esi, 0 #, movabs rax, OFFSET FLAT:_Z10Intrpt_AllPll # tmp61, call rax # JMP !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .cfi_endproc .LFE4: .size _Z8Intrpt_0v, .-_Z8Intrpt_0v .ident "GCC: (GNU) 4.7.2" .section .note.GNU-stack,"",@progbits ===END===