public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "theodort at inf dot ethz.ch" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110080] New: [13/14 Regression] Missed Dead Code Elimination at -Os when using __builtin_unreachable since r13-6945-g429a7a88438 Date: Thu, 01 Jun 2023 13:54:43 +0000 [thread overview] Message-ID: <bug-110080-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110080 Bug ID: 110080 Summary: [13/14 Regression] Missed Dead Code Elimination at -Os when using __builtin_unreachable since r13-6945-g429a7a88438 Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: theodort at inf dot ethz.ch Target Milestone: --- Given: void foo(void); static unsigned char a = 131; static int *b; static int **c = &b; static void d(int e, unsigned f) { int *g; if (e){ for (; a; ++a) for (e = 0; 0;) ; g = &e; int **h = &g; if (**h) { foo(); } } *c = &e; } int main() { d(4 & a, a); } gcc trunk/13.1/12.3 at -Os generate: main: testb $4, a(%rip) je .L3 movb $0, a(%rip) .L3: leaq -4(%rsp), %rax movq %rax, b(%rip) xorl %eax, %eax ret a: .byte -125 If I include a __builtin_unreachable() to help the compiler: void foo(void); static unsigned char a = 131; static int *b; static int **c = &b; static void d(int e, unsigned f) { int *g; if (f != 131) { __builtin_unreachable(); // <- THIS } if (!e){ for (; a; ++a) for (e = 0; 0;) ; g = &e; int **h = &g; if (**h) { foo(); } } *c = &e; } int main() { d(4 & a, a); } gcc-12.3 at -Os generates better code: main: leaq -4(%rsp), %rax movb $0, a(%rip) movq %rax, b(%rip) xorl %eax, %eax ret a: .byte -125 But gcc-13.1/trunk at -Os generate worse code: main: subq $24, %rsp movb a(%rip), %al movl %eax, %edx andl $4, %edx movl %edx, 12(%rsp) xorl %edx, %edx .L2: testb %al, %al je .L8 incl %eax movb $1, %dl jmp .L2 .L8: testb %dl, %dl je .L4 movb $0, a(%rip) jmp .L5 .L4: cmpl $0, 12(%rsp) je .L5 call foo .L5: leaq 12(%rsp), %rax movq %rax, b(%rip) xorl %eax, %eax addq $24, %rsp ret a: .byte -125 https://godbolt.org/z/zvqshjEj3 Started with r13-6945-g429a7a88438
next reply other threads:[~2023-06-01 13:54 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-06-01 13:54 theodort at inf dot ethz.ch [this message] 2023-06-01 14:02 ` [Bug tree-optimization/110080] " theodort at inf dot ethz.ch 2023-06-02 7:53 ` rguenth at gcc dot gnu.org 2023-07-27 9:26 ` rguenth at gcc dot gnu.org 2023-08-21 23:20 ` pinskia at gcc dot gnu.org 2023-08-21 23:21 ` pinskia at gcc dot gnu.org 2023-09-19 14:30 ` cvs-commit at gcc dot gnu.org 2023-09-19 15:03 ` amacleod at redhat dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-110080-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).