https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126706
Bug ID: 126706
Summary: `(int)(float)(int)(unsigned short)a` should be
optimized to `(int)(unsigned short)a`
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Target: aarch64 x86_64
Take:
```
_BitInt(32) f(unsigned _BitInt(16) t1)
{
_BitInt(32) t = t1;
_Float32 tt = t;
return tt;
}
```
This should be optimized to just return t1; as the range of t fits into float.
Note I used C's _BitInt here so I can be explict about the precision.
That is this:
```
/* If we are converting an integer to a floating-point that can
represent it exactly and back to an integer, we can skip the
floating-point conversion. */
(if (GIMPLE /* PR66211 */
&& inside_int && inter_float && final_int &&
(unsigned) significand_size (TYPE_MODE (inter_type))
>= inside_prec - !inside_unsignedp)
(convert @0)))))))
```
Could use some range info