public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106379] New: DCE depends on order
@ 2022-07-21  9:13 tmayerl at student dot ethz.ch
  2022-07-21  9:48 ` [Bug tree-optimization/106379] " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: tmayerl at student dot ethz.ch @ 2022-07-21  9:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106379
           Summary: DCE depends on order
           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 the
order of the sub-expressions within the if.

GCC detects that the if expression in the following code snippet evaluates 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 c, bool s) {
    if (((!c == !s) && !(c) && s)) {
        DCEMarker0_();
    }
}

In the following snippet the expressions are swapped (the semantics stay the
same). 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 c, bool s) {
    if ((!s == !c) && s && !(c)) {
        DCEMarker0_();
    }
}


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

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

end of thread, other threads:[~2023-09-17  5:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-21  9:13 [Bug c/106379] New: DCE depends on order tmayerl at student dot ethz.ch
2022-07-21  9:48 ` [Bug tree-optimization/106379] " rguenth at gcc dot gnu.org
2022-07-21 11:23 ` rguenth at gcc dot gnu.org
2022-07-21 11:24 ` cvs-commit at gcc dot gnu.org
2022-08-08 20:36 ` amacleod at redhat dot com
2023-05-18 17:26 ` pinskia at gcc dot gnu.org
2023-07-13 18:39 ` pinskia at gcc dot gnu.org
2023-09-17  5:46 ` 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).