https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126048
Bug ID: 126048
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: ---
cat prog.c
int src(int v1_u8) {
if (!((1 <= v1_u8) && (v1_u8 <= 16))) __builtin_unreachable();
int i0_u8 = v1_u8 << v1_u8;
int i1_u8 = i0_u8 / v1_u8;
return i1_u8;
}
GCC truck at O3 cannot optimize the C program (not a regression), but Clang
truck at O3 can.
Reproducer: https://godbolt.org/z/fhGWYT8xs
Possible: `(x << x) / x` ==> `1 << x`
GCC at O3:
"src":
mov ecx, edi
mov eax, edi
sal eax, cl
cdq
idiv edi
ret
LLVM at O3:
src:
mov ecx, edi
mov eax, 1
shl eax, cl
ret