Bug 106381 - DCE depends on used programming language (C vs C++)
Summary: DCE depends on used programming language (C vs C++)
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 12.1.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on: 106379
Blocks:
  Show dependency treegraph
 
Reported: 2022-07-21 09:33 UTC by Thomas Mayerl
Modified: 2023-10-25 22:43 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-05-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Mayerl 2022-07-21 09:33:07 UTC
In some cases, the compiler's ability to eliminate dead code depends on the used language (C vs C++).

GCC detects that the if expression in the following code snippet evaluates to false and thus removes the dead code. The code is compiled as C++ code:

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

static void __attribute__ ((noinline)) DCEMarker0_() {printf("DCE2.0");}

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

However, if the same code is compiled as C code, GCC cannot eliminate the dead code anymore.

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

(Might be related to 106379 and 106380)
Comment 1 Andrew Pinski 2023-05-18 17:23:15 UTC
Actually it is worse in GCC 13. Both the C and C++ front-ends produced IR does not get optimized.
Comment 2 Xi Ruoyao 2023-05-19 06:48:38 UTC
Even if we change "unsigned" to "bool", it still does not get optimized with GCC 13.

So generally should we try to solve 2-SAT if a boolean expression is a 2-SAT form?