From 075b88a514233e5c0ff877ddb27e756641b330d1 Mon Sep 17 00:00:00 2001
From: Changpeng Fang <chfang@houghton.(none)>
Date: Thu, 12 Aug 2010 10:08:54 -0700
Subject: [PATCH] pr45241 give up dot_prod pattern searching if stmt is outside the loop.
* tree-vect-patterns.c (vect_recog_dot_prod_pattern): Give
up dot_prod pattern searching if a stmt is outside the loop.
* gcc.dg/vect/no-tree-pre-pr45241.c: New.
---
gcc/testsuite/gcc.dg/vect/no-tree-pre-pr45241.c | 20 ++++++++++++++++++++
gcc/tree-vect-patterns.c | 5 +++++
2 files changed, 25 insertions(+), 0 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/vect/no-tree-pre-pr45241.c
new file mode 100644
@@ -0,0 +1,20 @@
+/* PR tree-optimization/45241 */
+/* { dg-do compile } */
+/* { dg-options "-O3 -fno-tree-pre" } */
+
+int
+foo (short x)
+{
+ short i, y;
+ int sum;
+
+ for (i = 0; i < x; i++)
+ y = x * i;
+
+ for (i = x; i > 0; i--)
+ sum += y;
+
+ return sum;
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */
@@ -255,6 +255,11 @@ vect_recog_dot_prod_pattern (gimple last_stmt, tree *type_in, tree *type_out)
prod_type = half_type;
stmt = SSA_NAME_DEF_STMT (oprnd0);
+
+ /* It could not be the dot_prod pattern if the stmt is outside the loop. */
+ if (!flow_bb_inside_loop_p (loop, gimple_bb (stmt)))
+ return NULL;
+
/* FORNOW. Can continue analyzing the def-use chain when this stmt in a phi
inside the loop (in case we are analyzing an outer-loop). */
if (!is_gimple_assign (stmt))
--
1.6.3.3