public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "tmayerl at student dot ethz.ch" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/106474] New: DCE depends on how if expressions are nested Date: Fri, 29 Jul 2022 08:24:57 +0000 [thread overview] Message-ID: <bug-106474-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106474 Bug ID: 106474 Summary: DCE depends on how if expressions are nested Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: tmayerl at student dot ethz.ch Target Milestone: --- In some cases, the compiler's ability to eliminate dead code depends on how if expressions are nested. GCC detects that the if expressions in the following code snippet evaluate to false and thus removes the dead code: #include <stdio.h> #include <stdbool.h> static void __attribute__ ((noinline)) DCEMarker0_() {printf("DCE2.0");} void f(bool s, bool c) { if (!c == !s) { if (!c && s) { DCEMarker0_(); } } } In the following snippet the !c term is moved into the outer if expression. However, GCC cannot eliminate the dead code anymore: #include <stdio.h> #include <stdbool.h> static void __attribute__ ((noinline)) DCEMarker0_() {printf("DCE2.0");} void f(bool s, bool c) { if ((!c == !s) && !c) { if (s) { DCEMarker0_(); } } } In the following snippet, only the outer if statement is kept and all terms are moved there. GCC is now able to eliminate the code again: #include <stdio.h> #include <stdbool.h> static void __attribute__ ((noinline)) DCEMarker0_() {printf("DCE2.0");} void f(bool s, bool c) { if (((!c == !s) && !c) && s) { DCEMarker0_(); } } This can also be seen via the following Compiler Explorer link: https://godbolt.org/z/9WPn5cG1W
next reply other threads:[~2022-07-29 8:24 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-07-29 8:24 tmayerl at student dot ethz.ch [this message] 2022-07-29 9:51 ` [Bug tree-optimization/106474] " rguenth at gcc dot gnu.org 2022-07-29 16:29 ` amacleod at redhat dot com 2022-08-02 18:32 ` cvs-commit at gcc dot gnu.org 2022-08-02 20:01 ` 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-106474-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).