<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56711>56711</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Expressions are better optimised by including a redundant term
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ThomasMayerl
      </td>
    </tr>
</table>

<pre>
    Sometimes expressions are better optimised by including a redundant term. The following if expression is always false:

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

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

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

LLVM cannot eliminate the dead code. In the following snippet, `!s` is replaced by `!s || 0`.

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

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

void f(bool x, bool s, bool c, bool r) {
    if (((c && !(c)) || (x && r && !(s))) && (!x == (!s || 0))) {
        DCEMarker0_();
    }
}
```

LLVM is now able to detect and to remove this dead code. 

Note: With LLVM 13 both snippets cannot be optimised. The described behaviour was observed using LLVM 14.0.5

The snippets and the compiled assembly instructions can also be compared on the following Compiler Explorer website: https://godbolt.org/z/o6E6MW69a
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztVUtv2zAM_jXOhZjhVxzn4MOapMCAZpcV6zGQLCbWpkiGJCfpfv0oO6922GnYTjMYmRQ_k5T0ieFGvNZfzB693KMDPHUWnZNGO2AWgaP3aMF05JYOBfBXkLpRvZB6Bwwsil4Lpj0QbB_Dc4uwNUqZY_DL7V1AkBRSHdmrgy1TDqP8Y5Qso-QylslZRjPLxzwIUb5wXkgTt1G--o2XG6Pu_cPoPPOygYORAjYb5r2VvPe42UCUVSTaSK2kxiibk8BysVoz-x1tshn8c4hmD52V2m8HOyNAFiekhA_yh2i2vM82pAnIUAucomwBg-auWnPV7Dn6-CXQQ1s1FkXSkFqS0CsN5rm-aLYgCbDTBWDfIt2IHMCXeQqYEj5fkgSYu0a7yx6eX5YflnhF3BZ7Vd4d2DA-PX1dQ8O0Nh5QEWc08wieWCGQCWiMwBg-6WHmxhOnZdehD9sT4oUiyyTwxWKnWDPS7uy5bEPIHP8n0D8nUPX2EG74v8cnIoI2R2BcEZUMMclj44FpESyLe3MIFCPUHcfug3w2PnQbeJG-hSFimtM2knEmnrtQluOt1Y3NTKBr6NQDBbFlB2l6C0fmwHCH9kDTvQsMHqMWcRJP7zOHCNccQ8E00Zh9JxV9ypzDPVehozpv-8YPbZdKoT7pTCgmQKkNCzDvr8xiDGJhdeqUsaQckTs5LrT1vnOhv2aPJDtD7FY-NnZH1g_6mXJVrl_KOZtgnZbTalZmVVlMRJ2LeU6zXnqF9eqP_gsmvVX1u0Jo_3se06LIUOpweX3orPlGR0qmdK5HYuHjtJyl6aSti2Sb5VXB87moRMOyZFuJeVPkaVEgF1U-UYyjcnU0faB7pfEIQ4hwx6bLiayzJMuSWTZNp9msyOMK2TwVfFokJWdJJqIiwT2TKg51hB2a2Hooifc7R04lnXc3J52Y3GnEIR3FZ71vja2fW7Nnbs1e0arJkL8e6v8JCGkj8A">