https://gcc.gnu.org/g:35b4c01575e15550b49c82fe146b2669db6320a7
commit r17-4920-g35b4c01575e15550b49c82fe146b2669db6320a7 Author: Richard Biener <[email protected]> Date: Mon Sep 28 15:44:47 2026 +0200 Do not treat COMPCODE_FALSE or COMPCODE_TRUE as trapping in combine_comparisons In combine_comparisons, under flag_trapping_math, we check whether the combined comparison traps under the same conditions as the input comparisons: bool trap = (compcode & COMPCODE_UNORD) == 0 && (compcode != COMPCODE_EQ) && (compcode != COMPCODE_ORD); When compcode is COMPCODE_FALSE or COMPCODE_TRUE trap is computed as true, and combine_comparisons errorneously eliminates IEEE exceptions. PR tree-optimization/53805 * fold-const.cc (combine_comparisons): Do not treat COMPCODE_FALSE or COMPCODE_TRUE as trapping. * gcc.dg/tree-ssa/fp-trapping-and-1.c: New testcase. Diff: --- gcc/fold-const.cc | 4 +++- gcc/testsuite/gcc.dg/tree-ssa/fp-trapping-and-1.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 113558973f6e..97c083efc813 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -3085,7 +3085,9 @@ combine_comparisons (enum tree_code code, enum tree_code lcode, && (rcompcode != COMPCODE_ORD); bool trap = (compcode & COMPCODE_UNORD) == 0 && (compcode != COMPCODE_EQ) - && (compcode != COMPCODE_ORD); + && (compcode != COMPCODE_ORD) + && (compcode != COMPCODE_FALSE) + && (compcode != COMPCODE_TRUE); /* In a short-circuited boolean expression the LHS might be such that the RHS, if evaluated, will never trap. For diff --git a/gcc/testsuite/gcc.dg/tree-ssa/fp-trapping-and-1.c b/gcc/testsuite/gcc.dg/tree-ssa/fp-trapping-and-1.c new file mode 100644 index 000000000000..84946dc7cc11 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/fp-trapping-and-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftrapping-math -fdump-tree-optimized" } */ + +int +f (double a, double b) +{ + return (a > b) & (a < b); +} + +/* { dg-final { scan-tree-dump-times " > " 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " < " 1 "optimized" } } */
