https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91789
Bug ID: 91789 Summary: Value ranges determined from comparisons not used transitively Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: drepper.fsp+rhbz at gmail dot com Target Milestone: --- Take the following code: int foo(int a, int b) { if (b < a) __builtin_unreachable(); if (a < 0) return -1; if (b < 0) return 0; return 1; } The compiler should be able to determine that the b < 0 can never be true. At that point in the code a >= 0 and b >= a, therefore transitively b >= 0. The problem is not tied to __builtin_unreachable as can be seen by changing the code slightly: int foo(int a, int b) { if (b < a) return 2; if (a < 0) return -1; if (b < 0) return 0; return 1; } After the initial test b < a is handled there is still a threeway comparison. The problem can be seen with 9.2.1 as well as the current trunk version. clang 8.0.0 generates pretty much the same code as gcc.