From 56e7010eef88d941c59e3d677b7bc67a890c210d Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 4 Sep 2025 09:33:58 +0200 Subject: tree-optimization/121768 - bogus double reduction detected The following changes how we detect double reductions, in particular not setting vect_double_reduction_def on the outer PHIs when the inner loop doesn't satisfy double reduction constraints. It also simplifies the setup a bit by not having to detect wheter we process an inner loop of a double reduction. PR tree-optimization/121768 * tree-vect-loop.cc (vect_inner_phi_in_double_reduction_p): Remove. (vect_analyze_scalar_cycles_1): Analyze inner loops of double reductions immediately and only mark fully recognized double reductions. Skip already analyzed inner loops. (vect_is_simple_reduction): Change double_reduc from a flag to an output of the inner loop PHI and to whether we are processing an inner loop of a double reduction. * gcc.dg/vect/pr121768.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr121768.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/vect/pr121768.c (limited to 'gcc/testsuite/gcc.dg') diff --git a/gcc/testsuite/gcc.dg/vect/pr121768.c b/gcc/testsuite/gcc.dg/vect/pr121768.c new file mode 100644 index 0000000..b302f79 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr121768.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fno-tree-dce -fno-inline" } */ + +int a, b, c; +char d(char p) { return p; } +int main () { + while (c) { + for (b = 2; b; b--) { + int *g = &a; + *g = d((d(*g) >= 128) | b); + } + c--; + } + return 0; +} -- cgit v1.1