https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83541
Bug ID: 83541 Summary: Missed optimization with int overflow Product: gcc Version: tree-ssa Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: zamazan4ik at tut dot by Target Milestone: --- gcc(trunk) with '-O3 -std=c++17 -ffast-math' for this: #include <limits> int test(int x) { if(x == std::numeric_limits<int>::max()) { return x+1; } return 42; } generates this: test(int): cmp edi, 2147483647 mov edx, -2147483648 mov eax, 42 cmove eax, edx ret But branch with condition is UB, so you can just delete it and simply return 42.