From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9324D385800C; Fri, 19 Feb 2021 06:46:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9324D385800C From: "sebastian.huber@embedded-brains.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/99151] Missed optimization: Superfluous stack frame and code with noreturn or __builtin_unreachable() Date: Fri, 19 Feb 2021 06:46:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: sebastian.huber@embedded-brains.de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Feb 2021 06:46:58 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99151 --- Comment #4 from Sebastian Huber --- (In reply to Andrew Pinski from comment #3) > Is the nop due to alignment? With -g and -coverage I get this code: sparc-rtems7-gcc -O2 -o - -S unreachable.c -fverbose-asm -g -coverage .file "unreachable.c" ! GNU C17 (GCC) version 11.0.0 20210205 (RTEMS 7, RSB 61dcadee0825867ebe51f9f367430ef75b8fe9c0, Newlib d4a756f) (sparc-rtems7) ! compiled by GNU C version 11.0.0 20201130 (experimental) [revision b46314c78061a5156bac44a317c87d32b00d4295], GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP ! GGC heuristics: --param ggc-min-expand=3D100 --param ggc-min-heapsize=3D1= 31072 ! options passed: -mcpu=3Dv7 -g -O2 -fprofile-arcs -ftest-coverage .section ".text" .LLtext0: .cfi_sections .debug_frame .align 4 .global g .type g, #function .proc 020 g: .LLFB0: .file 1 "unreachable.c" .loc 1 5 1 view -0 .cfi_startproc save %sp, -96, %sp ! .cfi_window_save .cfi_register 15, 31 .cfi_def_cfa_register 30 sethi %hi(__gcov0.g), %g1 !, tmp112 ldd [%g1+%lo(__gcov0.g)], %i4 ! __gcov0.g[0], __gcov0.g[0] addcc %i5, 1, %g3 ! __gcov0.g[0],, tmp115 addx %i4, 0, %g2 ! __gcov0.g[0],, .loc 1 6 9 view .LLVU1 call r, 0 !, .LLVL0: std %g2, [%g1+%lo(__gcov0.g)] ! tmp115, __gcov0.g[0] nop In the the no-return function case, this nop has no line debug information = and there is no profiling counter increment. .cfi_endproc .LLFE0: .size g, .-g .align 4 .global f .type f, #function .proc 020 f: .LLFB1: .loc 1 11 1 view -0 .cfi_startproc save %sp, -96, %sp ! .cfi_window_save .cfi_register 15, 31 .cfi_def_cfa_register 30 sethi %hi(__gcov0.f), %g1 !, tmp114 ldd [%g1+%lo(__gcov0.f)], %i2 ! __gcov0.f[0], __gcov0.f[0] addcc %i3, 1, %g3 ! __gcov0.f[0],, tmp117 addx %i2, 0, %g2 ! __gcov0.f[0],, or %g1, %lo(__gcov0.f), %i5 ! tmp114,, tmp113 .loc 1 12 9 view .LLVU3 call u, 0 !, .LLVL1: std %g2, [%g1+%lo(__gcov0.f)] ! tmp117, __gcov0.f[0] ldd [%i5+8], %i2 ! __gcov0.f[1], __gcov0.f[1] addcc %i3, 1, %g3 ! __gcov0.f[1],, tmp123 addx %i2, 0, %g2 ! __gcov0.f[1],, std %g2, [%i5+8] ! tmp123, __gcov0.f[1] .loc 1 13 9 view .LLVU4 .cfi_endproc .LLFE1: .size f, .-f In the __builtin_unreachable() case we don't have a nop, but a profiling counter increment is there. clang 9 generates this code: clang -O2 -o - -S unreachable.c -fverbose-asm -g -coverage --target=3Dsparc .text .file "unreachable.c" .globl g ! -- Begin function g .p2align 2 .type g,@function g: ! @g .Lfunc_begin0: .file 1 "/home/EB/sebastian_h/src/rtems/unreachable.c" .loc 1 5 0 ! unreachable.c:5:0 .cfi_startproc ! %bb.0: save %sp, -96, %sp .cfi_def_cfa_register %fp .cfi_window_save .cfi_register 15, 31 .Ltmp0: .loc 1 6 9 prologue_end ! unreachable.c:6:9 sethi %hi(__llvm_gcov_ctr), %i0 ldd [%i0+%lo(__llvm_gcov_ctr)], %i2 addcc %i3, 1, %i5 addxcc %i2, 0, %i4 call r std %i4, [%i0+%lo(__llvm_gcov_ctr)] .Ltmp1: .Lfunc_end0: .size g, .Lfunc_end0-g .cfi_endproc ! -- End function .globl f ! -- Begin function f .p2align 2 .type f,@function f: ! @f .Lfunc_begin1: .loc 1 11 0 ! unreachable.c:11:0 .cfi_startproc ! %bb.0: save %sp, -96, %sp .cfi_def_cfa_register %fp .cfi_window_save .cfi_register 15, 31 .Ltmp2: .loc 1 12 9 prologue_end ! unreachable.c:12:9 sethi %hi(__llvm_gcov_ctr.1), %i0 ldd [%i0+%lo(__llvm_gcov_ctr.1)], %i2 addcc %i3, 1, %i5 addxcc %i2, 0, %i4 call u std %i4, [%i0+%lo(__llvm_gcov_ctr.1)] .Ltmp3: .Lfunc_end1: .size f, .Lfunc_end1-f .cfi_endproc ! -- End function There are no nops and no unreachable profiling counter increments.=