https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125811
Drea Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Keywords| |easyhack,
| |missed-optimization
Ever confirmed|0 |1
Last reconfirmed| |2026-06-16
Status|UNCONFIRMED |NEW
Summary|Possible Missed |`a * (1 << b)` is not
|Optimization at O3 |transformed into `a << b`
| |in some cases
--- Comment #1 from Drea Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
This pattern:
```
/* Fold (a * (1 << b)) into (a << b) */
(simplify
(mult:c @0 (convert? (lshift integer_onep@1 @2)))
(if (! FLOAT_TYPE_P (type)
&& tree_nop_conversion_p (type, TREE_TYPE (@1)))
(lshift @0 @2)))
```
Only supports nop conversion But in this case we have a truncating conversion:
```
_1 = (intD.7) v0_u8_3(D);
_2 = 1 << _1;
i0_u8_4 = (uint8_tD.4679) _2;
i1_u8_5 = v0_u8_3(D) * i0_u8_4;
```
I think we can do the conversion and truncate afterwards.
So it becomes (convert (lshift (convert @0) @2))