https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127920
Bug ID: 127920
Summary: Possible missed optimization at O3
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: apowenq at gmail dot com
Target Milestone: ---
Reproducer: https://godbolt.org/z/acf4G4T8d
$cat prog.c
int src(int v0, int v1, int v2) {
if (!(32 <= v0 && v0 <= 33)) __builtin_unreachable();
if (!(1 <= v1 && v1 <= 3)) __builtin_unreachable();
if (!(228 <= v2 && v2 <= 229)) __builtin_unreachable();
int i0 = v0 / v1;
int i1 = i0 & 32;
int i2 = v2 | i1;
return i2;
}
GCC can infer the right ranges, but cannot optimize v2|i1 to v2:
```
# RANGE [irange] int [0, 0][32, 32] MASK 0x20 VALUE 0x0
i1_11 = i0_10 & 32;
# RANGE [irange] int [228, 229] MASK 0x1 VALUE 0xe4
i2_12 = v2_9(D) | i1_11;
```
GCC at O3:
"src":
mov eax, edi
mov ecx, edx
cdq
idiv esi
and eax, 32
or eax, ecx
ret
LLVM at O3:
src:
mov eax, edx
ret