https://gcc.gnu.org/g:b85f2169fb3b0a25b5e53974775df3086d900376
commit r17-6427-gb85f2169fb3b0a25b5e53974775df3086d900376 Author: Andrew MacLeod <[email protected]> Date: Tue Nov 17 12:16:01 2026 -0500 range_of_phi should process all arguments. Range_of_phi was accumulating the range of any equivalences seperately fromt he main range, and then combining them with the main range if there were nothing but a single equivlaence at the end. This wasn't actually saving anything. we still perform a union on each argument with a range, and as the PR show, we lose the +/- 0.0 range on occasion. There is also a window for wrongness if not all arguments are the same equivalence, and the equivalent argument does not have a range yet. I don't thinkthis would ever trigger, and I also do not think thre is any benefit to the current approach as any equivalence never gets used in any other way. Its easier to simply process each argument and union in the range. It also turns out to be .025% faster as well. PR tree-optimization/128687 gcc/ * gimple-range-fold.cc (fold_using_range::range_of_phi): Accumulate the range of every argument unconditionally. gcc/testsuite/ * gcc.dg/torture/pr128687.c: New. Diff: --- gcc/gimple-range-fold.cc | 15 +-------------- gcc/testsuite/gcc.dg/torture/pr128687.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index ea26f07b0a4f..5e8ef0af1b7a 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -1429,7 +1429,6 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) tree phi_def = gimple_phi_result (phi); tree type = gimple_range_type (phi); value_range arg_range (type); - value_range equiv_range (type); unsigned x; if (!type) @@ -1439,7 +1438,6 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) tree single_arg = NULL_TREE; bool seen_arg = false; - relation_oracle *oracle = &(src.query()->relation ()); // Start with an empty range, unioning in each argument's range. r.set_undefined (); for (x = 0; x < gimple_phi_num_args (phi); x++) @@ -1456,15 +1454,8 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) if (!arg_range.undefined_p ()) { + r.union_ (arg_range); // Register potential dependencies for stale value tracking. - // Likewise, if the incoming PHI argument is equivalent to this - // PHI definition, it provides no new info. Accumulate these ranges - // in case all arguments are equivalences. - if (oracle->query (e, arg, phi_def) == VREL_EQ) - equiv_range.union_(arg_range); - else - r.union_ (arg_range); - if (gimple_range_ssa_p (arg) && src.gori_ssa ()) src.gori_ssa ()->register_dependency (phi_def, arg); } @@ -1483,10 +1474,6 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) break; } - // If all arguments were equivalences, use the equivalence ranges as no - // arguments were processed. - if (r.undefined_p () && !equiv_range.undefined_p ()) - r = equiv_range; // If the PHI boils down to a single effective argument, look at it. if (single_arg) diff --git a/gcc/testsuite/gcc.dg/torture/pr128687.c b/gcc/testsuite/gcc.dg/torture/pr128687.c new file mode 100644 index 000000000000..13a32c54d537 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr128687.c @@ -0,0 +1,27 @@ +/* { dg-do run } */ +/* { dg-additional-options "-fsigned-zeros" } */ + +__attribute__((noipa)) int +f (int n, double m) +{ + double x = 0.0; + int s = 0; + int i; + for (i = 0 ; i < n; i++) + { + double y = x * m; /* m == -1.0: x is +0.0, then -0.0. */ + if (y != x) + break; + s += __builtin_signbit (x) != 0; + x = y; + } + return s; +} + +int +main (void) +{ + if (f (2, -1.0) != 1) + __builtin_abort (); + return 0; +}
