https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97603
Bug ID: 97603 Summary: Failure to optimize out compare into reuse of subtraction result Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gabravier at gmail dot com Target Milestone: --- int g(); int f(int a, int b) { if (a != b) return a - b; return g(); } This can be optimized to using the result of `a - b` to check for `a != b`. This is done by LLVM, but not by GCC. For example, on x86, LLVM generates this : f(int, int): sub edi, esi jne .LBB0_1 jmp g() .LBB0_1: mov eax, edi ret GCC generates this : f(int, int): cmp edi, esi je .L7 mov eax, edi sub eax, esi ret .L7: jmp g()