https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126644
Bug ID: 126644
Summary: `a << CST >> CST` can be simplified into a if upper
CST bits are not set
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: easyhack, missed-optimization, TREE
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
int h0 (int x, int y, unsigned short *a)
{
return *a << 3 >> 3;
}
```
This should just be simplified into *a on the tree level.
Currently combine does it:
```
Trying 9 -> 10:
9: r110:SI=r109:SI<<0x3
REG_DEAD r109:SI
10: r108:SI=r110:SI>>0x3
REG_DEAD r110:SI
Successfully matched this instruction:
(set (reg:SI 108 [ _6 ])
(reg:SI 109 [ _2 ]))
```
It does via the non-zero bits. A similar thing can be done for match.
Noticed while reviewing
https://gcc.gnu.org/pipermail/gcc-patches/2026-August/726305.html .