https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126046
Bug ID: 126046
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 v0_u8, int v2_u8) {
if (!((8 <= v0_u8) && (v0_u8 <= 10))) __builtin_unreachable();
if (!((0 <= v2_u8) && (v2_u8 <= 1))) __builtin_unreachable();
int i0_u8 = v0_u8 - v2_u8;
int i1_u8 = v0_u8 / i0_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/qe5T576rf
GCC at O3:
"src":
mov eax, edi
mov ecx, edi
sub ecx, esi
cdq
idiv ecx
ret
LLVM at O3:
src:
mov eax, 1
ret