https://gcc.gnu.org/g:8ff59a95b8a24f002072e5ea8797156edeccfb35
commit r17-5765-g8ff59a95b8a24f002072e5ea8797156edeccfb35 Author: Richard Biener <[email protected]> Date: Fri Oct 30 15:38:16 2026 +0100 tree-optimization/128250 - reassoc and abnormals This adds a few missing checks on is_reassociable_op to avoid re-scheduling abnormal SSA uses, breaking out-of-SSA coalescing. PR tree-optimization/128250 * tree-ssa-reassoc.cc (acceptable_pow_call): Ensure base satisfies can_reassociate_op_p. (try_special_add_to_ops): Likewise for negated operand. * gcc.dg/torture/pr128250.c: New test. Diff: --- gcc/testsuite/gcc.dg/torture/pr128250.c | 17 +++++++++++++++++ gcc/tree-ssa-reassoc.cc | 6 +++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr128250.c b/gcc/testsuite/gcc.dg/torture/pr128250.c new file mode 100644 index 000000000000..eaef60ada4d8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr128250.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target nonlocal_goto } */ + +#include <setjmp.h> + +extern int bar (unsigned int *); +extern jmp_buf *baz (void); +struct C { int c1; }; +void foo (struct C *x, int *z, int e) +{ + unsigned int d = 0; + long f; + setjmp (*baz()); + f = 1 + ~d; + d = 8; + if ((!0) && !e && bar(z)) *z = *z = 1 + f + f; +} diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc index 858f9f906ede..63a37c38a4bf 100644 --- a/gcc/tree-ssa-reassoc.cc +++ b/gcc/tree-ssa-reassoc.cc @@ -6152,7 +6152,9 @@ acceptable_pow_call (gcall *stmt, tree *base, HOST_WIDE_INT *exponent) /* Expanding negative exponents is generally unproductive, so we don't complicate matters with those. Exponents of zero and one should have been handled by expression folding. */ - if (*exponent < 2 || TREE_CODE (*base) != SSA_NAME) + if (*exponent < 2 + || TREE_CODE (*base) != SSA_NAME + || !can_reassociate_op_p (*base)) return false; return true; @@ -6193,6 +6195,8 @@ try_special_add_to_ops (vec<operand_entry *> *ops, || !DECIMAL_FLOAT_MODE_P (element_mode (op)))) { tree rhs1 = gimple_assign_rhs1 (def_stmt); + if (!can_reassociate_op_p (rhs1)) + return false; tree cst = build_minus_one_cst (TREE_TYPE (op)); add_to_ops_vec (ops, rhs1); add_to_ops_vec (ops, cst);
