https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89518
Bug ID: 89518 Summary: missed optimisation for array address calculations Product: gcc Version: 8.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: arnaud02 at users dot sourceforge.net Target Milestone: --- Considering: int f(int index, int stride) { const int i1 = index / stride; const int i2 = index % stride; const int index2 = i1*stride+i2; return index2; // expect: index2 = index } gcc 8.3 with "-O3" on x84_64 emits: f(int, int): mov eax, edi cdq idiv esi imul eax, esi add eax, edx ret By contrast, clang 7 with "-O3" emits f(int, int): mov eax, edi ret MSVC 2017 with "/O2" emits: int f(int,int) mov eax, ecx ret 0 Is there a way to persuade gcc to simplify this expression at compile time?