public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/106570] New: DCE sometimes fails with depending if statements
@ 2022-08-09 11:35 tmayerl at student dot ethz.ch
  2022-08-09 13:15 ` [Bug tree-optimization/106570] [12/13 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75 marxin at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: tmayerl at student dot ethz.ch @ 2022-08-09 11:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106570

            Bug ID: 106570
           Summary: DCE sometimes fails with depending if statements
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tmayerl at student dot ethz.ch
  Target Milestone: ---

Sometimes, DCE fails when multiple if statements are used. 

For example, GCC detects that the following if statements always evaluate to
false and thus removes the dead code:

#include <stdio.h>
#include <stdbool.h>

void DCEMarker0_();

void f(bool s, bool c) {
    if (!c == !s) {
        if (s && !c) {
            DCEMarker0_();
        }
    }
}

In the next snippet, the if statements are used to set a variable. This
variable is then used in the next if statement. However, GCC now fails to
detect and eliminate the dead code:

#include <stdio.h>
#include <stdbool.h>

void DCEMarker0_();

void f(bool s, bool c) {
    int intermediate_result = 0;
    if (!c == !s) {
        if (s && !c) {
            intermediate_result = 1;
        }
    }
    if (((!c == !s) && (s && !c)) || intermediate_result) {
        DCEMarker0_();
    }
}

This is actually a regression: It works fine until GCC 11.3.

This can also be seen via the following Compiler Explorer link:
https://godbolt.org/z/n9dKMfqsd

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-07-13 18:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-09 11:35 [Bug tree-optimization/106570] New: DCE sometimes fails with depending if statements tmayerl at student dot ethz.ch
2022-08-09 13:15 ` [Bug tree-optimization/106570] [12/13 Regression] DCE sometimes fails with depending if statements since r12-2305-g398572c1544d8b75 marxin at gcc dot gnu.org
2022-08-09 13:28 ` amacleod at redhat dot com
2022-08-09 13:48 ` rguenth at gcc dot gnu.org
2022-08-10 13:53 ` rguenth at gcc dot gnu.org
2023-03-11 17:07 ` pinskia at gcc dot gnu.org
2023-03-14 13:16 ` marxin at gcc dot gnu.org
2023-05-08 12:25 ` [Bug tree-optimization/106570] [12/13/14 " rguenth at gcc dot gnu.org
2023-07-13 18:38 ` pinskia at gcc dot gnu.org

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).