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)
Actually it is worse in GCC 13. Both the C and C++ front-ends produced IR does not get optimized.
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?