<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/66733>66733</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`(a == 0) & (((short)a) >= 0)` is not always optimized to just `a == 0`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pinskia
</td>
</tr>
</table>
<pre>
Take:
```
int f(int a)
{
short b = a;
_Bool t = a == 0;
_Bool t1 = b >= 0;
return t & t1;
}
void f0(int a, int *b)
{
*b= f(a) != 0;
}
void f01(int a, int *b)
{
_Bool c = f(a);
*b= c;
}
void f01_(int a, _Bool *b)
{
_Bool c = f(a);
*b= c;
}
_Bool f00(int a)
{
return f(a);
}
void f00_(int a, _Bool *b)
{
_Bool c = f00(a);
*b= c;
}
_Bool f1(int a)
{
_Bool t = a == 0;
short t1 = a;
_Bool t2 = t1 >= 0;
return t & t2;
}
```
`f`, `f00` and `f1` should all produce the same optimized code of just `a == 0;` While `f0`, `f01`, `f01_` and `f00_` all should produce `*b = a == 0;` But currently `f`, `f0`, f01` all still have the short comparison `>=` being included.
I am filing this because the way LLVM is acting here seems like `((short)a) < 0` is being transformed too early to `(a >> 15) & 1` and then never going back sometimes. This happens on x86_64, aarch64, riscv and BPF targets.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVVFv4zYM_jXyC3GBLCdO_OCHpmmAATdgD4ftsaBlOtZVtgJJTpf9-kGysqZpe9uuRmBTIfV9_EjaQufUYSSq2WrLVrsMJ98bWx_V6J4UZo1pz_U3fCJW3DG-Y_yOlTz94lKNHjomNuGJTFQpaL2dDXC9sR4aYMUOkBWXv9P1uDVGg5-94R4M_lFYHuMC1sNNnCU_2TEAiRJ8_o-DrXezcTKqhY6_JHoPwWDirnkn6XRFb7GL-oI2YCJ_TXyLn_8_glmXhGuSF1EXevkx3eM134z2GcYb3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