tree-optimization/111125 - properly cost BB reduction remain stmt handling

Message ID 20230824093708.71A883856DD0@sourceware.org
State Accepted
Headers
Series tree-optimization/111125 - properly cost BB reduction remain stmt handling |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Richard Biener Aug. 24, 2023, 9:36 a.m. UTC
  We assume that all root stmts which compose the total reduction chain
are vectorized but fail to account for the cost of adding back the
scalar defs we are not vectorizing.  The following rectifies this,
fixing the gcc.dg/tree-ssa/slsr-11.c FAIL on aarch64.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/111125
	* tree-vect-slp.cc (vectorizable_bb_reduc_epilogue): Account
	for the remain_defs processing.
---
 gcc/tree-vect-slp.cc | 5 +++++
 1 file changed, 5 insertions(+)
  

Patch

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index cc799b6ebcd..ace0ff3ef60 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -6433,6 +6433,11 @@  vectorizable_bb_reduc_epilogue (slp_instance instance,
 		    vectype, 0, vect_body);
   record_stmt_cost (cost_vec, 1, vec_to_scalar, instance->root_stmts[0],
 		    vectype, 0, vect_body);
+
+  /* Since we replace all stmts of a possibly longer scalar reduction
+     chain account for the extra scalar stmts for that.  */
+  record_stmt_cost (cost_vec, instance->remain_defs.length (), scalar_stmt,
+		    instance->root_stmts[0], 0, vect_body);
   return true;
 }