https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92712
Bug ID: 92712 Summary: Performance regression with assumed values Product: gcc Version: 9.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: mike.k at digitalcarbide dot com Target Milestone: --- The following code generates progressively worse code from GCC 7.5 to GCC 8.3 to GCC 9.1 (and trunk): static void func_base(int t, const int v) { int x = 0; for (int i = 0; i < t; ++i) { x += v; } volatile int d = x; } void func_default(int t, const int v) { func_base(t, v); } void func_assumed(int t, const int v) { if (t < 0) __builtin_unreachable(); func_base(t, v); } On GCC 7.5 (-O2): func_default(int, int): test edi, edi jle .L3 imul edi, esi mov DWORD PTR [rsp-4], edi ret .L3: xor edi, edi mov DWORD PTR [rsp-4], edi ret func_assumed(int, int): imul edi, esi mov DWORD PTR [rsp-4], edi ret On GCC 8.3 (-O2): func_default(int, int): test edi, edi jle .L3 imul edi, esi mov DWORD PTR [rsp-4], edi ret .L3: xor edi, edi mov DWORD PTR [rsp-4], edi ret func_assumed(int, int): test edi, edi je .L6 imul edi, esi .L6: mov DWORD PTR [rsp-4], edi ret On GCC 9.1 and trunk (-O2): func_default(int, int): test edi, edi jle .L3 sub edi, 1 imul edi, esi add esi, edi mov DWORD PTR [rsp-4], esi ret .L3: xor esi, esi mov DWORD PTR [rsp-4], esi ret func_assumed(int, int): test edi, edi je .L6 sub edi, 1 imul edi, esi add edi, esi .L6: mov DWORD PTR [rsp-4], edi ret This occurs regardless of if `func_base` is allowed to inline, or if it is manually inlined. It does not occur in LLVM-Clang or in Microsoft Visual C++.