<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56654>56654</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
DCE depends on order
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ThomasMayerl
</td>
</tr>
</table>
<pre>
In some cases, the compiler's ability to eliminate dead code depends on the order of the sub-expressions within the if.
LLVM 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(unsigned c, unsigned s) {
if (s && !s && !c) {
DCEMarker0_();
}
}
```
In the following snippet the order of the sub-expressions is changed. However, LLVM cannot eliminate the dead code anymore:
```
#include <stdio.h>
#include <stdbool.h>
static void __attribute__ ((noinline)) DCEMarker0_() {printf("DCE2.0");}
void f(unsigned c, unsigned s) {
if (!s && !c && s) {
DCEMarker0_();
}
}
```
Note: This difference can only be seen if the datatype is set to unsigned instead of bool (Might be related to: #56653)
This can also be seen via the following Compiler Explorer link: https://godbolt.org/z/e9esTxrdj (clang 14.0.0)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztVE1vozAQ_TVwsYqISUJy4NAmrbZSs6dqr5HBA7h1bOQxabO_fsfki0212sseFxnj0cx4nv0eU1p5KJ4NQ7sDVgkEjPiK-ZYMu-uUBhfxHJkolVb-wLxloNVOGeGBSRCSwmRYdWAkMmuGVOskOGbrwcC-vIPPzgGisgbZh_KtOsapOonSdZTeH-eXlx8b2spD5ZH8wp-C2DWdnTJrq7X9UKY51kejug48g73QPUHDALQWGoEJIymjR-ZgZ_fB046QR9n9GEE0T0_jaPJMmUr3VCHKVuilskkbZY9_8JbW6rF_mNELryq2t0qy7VZ471TZe9huWcQXNIxVRisDEV_SYOvV40a4d3DpdvAvWZQ_dE4ZXw82pwCepLQICdlDlK_H1YYyIbI3qBoDdMrA58XC047HaEYPXS-FI01zGvSZjNfVl_jwfAEZgFwirpAui5trHebnWybPJP5VQQpZ1QrTgEzYN_sB-yDSFRvkUwljrB-J9De6SQ2HnXX_aT_Rfsv2ef01_p_R_t36cP3stSUapaprcGCq0HsMtQ99YCURDmACwoE7QTd56CCwjkEd9nosZdAHakkngYRwoo1qWh_2cKCJfvr3bahGpM3m81kWQI_ADCBCZWoV9lJ5r8SNNFenXsgePztN-nGMuHsPG7fedxjkxJ9oNJbUoH1iXUPWT3phCfj66eRbAFdpUi2bTJM0UHlCEssik8tsKWKvvIaCbnncT4c_Ie6dLm5KURvty4S6NBla78-fu87ZN-qgZCrEPvTzp3D0adwW-SydLKZlWtWCCs6rfJaLukwzWcKimpVprEUJGoto9hDN1rEqeMp5mvPJJOOLbJnkvFzw-Vzm02lZZ4ssmqawE0onoXA4dOyKAUPZN0hOrdDj1Slw4A3O-4vet9YVr63dCdyIAzgdD5iLAfAvawT9dw">