Patchwork Fix PR45971: do not predicate condition phi nodes that are scev analyzable.

login
register
mail settings
Submitter Sebastian Pop
Date Nov. 9, 2010, 10:18 p.m.
Message ID <AANLkTikYUSERr7kQw5nB4DnFBJEE+K14Q2BiF7kuUiNU@mail.gmail.com>
Download mbox | patch
Permalink /patch/70581/
State New
Headers show

Comments

Sebastian Pop - Nov. 9, 2010, 10:18 p.m.
Hi,

This patch avoids the generation of a COND_EXPR when the condition
phi node is analyzable with scev.  Bootstrapped and tested on amd64-linux.
Ok for trunk?

Thanks,
Sebastian
Richard Guenther - Nov. 10, 2010, 11:03 a.m.
On Tue, 9 Nov 2010, Sebastian Pop wrote:

> Hi,
> 
> This patch avoids the generation of a COND_EXPR when the condition
> phi node is analyzable with scev.  Bootstrapped and tested on amd64-linux.
> Ok for trunk?

Ok.

Thanks,
Richard.

Patch

From 43f56c461f3797d4840f88ca6ecc2fe30a67c210 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Tue, 9 Nov 2010 14:02:06 -0600
Subject: [PATCH] Fix PR45971: do not predicate condition phi nodes that are scev analyzable.

2010-11-09  Sebastian Pop  <sebastian.pop@amd.com>

	PR tree-optimization/45971
	* tree-if-conv.c (predicate_scalar_phi): Do not generate a COND_EXPR
	for phi nodes analyzable by scev.

	* gcc.dg/vect/O3-pr45971.c: New.
---
 gcc/ChangeLog                          |    6 ++++++
 gcc/testsuite/ChangeLog                |    5 +++++
 gcc/testsuite/gcc.dg/vect/O3-pr45971.c |   13 +++++++++++++
 gcc/tree-if-conv.c                     |   10 +++++++---
 4 files changed, 31 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/O3-pr45971.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index dbf4ef6..3153dc6 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,11 @@ 
 2010-11-09  Sebastian Pop  <sebastian.pop@amd.com>
 
+	PR tree-optimization/45971
+	* tree-if-conv.c (predicate_scalar_phi): Do not generate a COND_EXPR
+	for phi nodes analyzable by scev.
+
+2010-11-09  Sebastian Pop  <sebastian.pop@amd.com>
+
 	PR tree-optimization/46036
 	* tree-if-conv.c (predicate_bbs): Call unshare_expr before
 	add_to_dst_predicate_list.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5517521..ee65f8f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@ 
 2010-11-09  Sebastian Pop  <sebastian.pop@amd.com>
 
+	PR tree-optimization/45971
+	* gcc.dg/vect/O3-pr45971.c: New.
+
+2010-11-09  Sebastian Pop  <sebastian.pop@amd.com>
+
 	PR tree-optimization/46036
 	* gfortran.dg/lto/pr46036_0.f90: New.
 
diff --git a/gcc/testsuite/gcc.dg/vect/O3-pr45971.c b/gcc/testsuite/gcc.dg/vect/O3-pr45971.c
new file mode 100644
index 0000000..1b7c65c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/O3-pr45971.c
@@ -0,0 +1,13 @@ 
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_int } */
+
+void
+foo (int *x, int *y)
+{
+  int i;
+  for (i = 0; i < 11; i++)
+    y[i] = (x[i] == 1) ? i + 1 : -(i + 1);
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */
+
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index 17b6672..fc65845 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -1224,7 +1224,7 @@  predicate_scalar_phi (gimple phi, tree cond,
 {
   gimple new_stmt;
   basic_block bb;
-  tree rhs, res, arg;
+  tree rhs, res, arg, scev;
 
   gcc_assert (gimple_code (phi) == GIMPLE_PHI
 	      && gimple_phi_num_args (phi) == 2);
@@ -1236,8 +1236,12 @@  predicate_scalar_phi (gimple phi, tree cond,
 
   bb = gimple_bb (phi);
 
-  arg = degenerate_phi_result (phi);
-  if (arg)
+  if ((arg = degenerate_phi_result (phi))
+      || ((scev = analyze_scalar_evolution (gimple_bb (phi)->loop_father,
+					    res))
+	  && !chrec_contains_undetermined (scev)
+	  && scev != res
+	  && (arg = gimple_phi_arg_def (phi, 0))))
     rhs = arg;
   else
     {
-- 
1.7.0.4