https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123311
Bug ID: 123311
Summary: Min(clz(a),clz(b))->clz(a|b) likewise for ctz
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
This works as long as the zero case is undefined I think. I am not 100% sure
what is the correct answer when zero is defined though.
Take:
```
typedef unsigned int u32;
#define clz __builtin_clzg
#define ctz __builtin_ctzg
#define min(x, y) x < y ? x : y
u32 src1(u32 x, u32 y) { return min(ctz(x), ctz(y)); }
u32 tgt1(u32 x, u32 y) { return ctz(x | y); }
u32 src2(u32 x, u32 y) { return min(clz(x), clz(y)); }
u32 tgt2(u32 x, u32 y) { return clz(x | y); }
```
src1 should optimize to tgt1. Likewise for src2 to tgt2.