From 35f74eaa5d4a79f3fcdfeae8bdf3b81751c6f1ba Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Wed, 16 Jun 2010 15:57:53 -0500
Subject: [PATCH 08/10] The predicate of a BB should either be a gimple_condexpr or an SSA_NAME.

	* tree-if-conv.c (add_to_predicate_list): Call force_gimple_operand
	when the predicate is not a gimple_condexpr.  Call reset_bb_predicate
	when the predicate is true.

	* gcc.dg/tree-ssa/ifc-6.c: New.
---
 gcc/testsuite/gcc.dg/tree-ssa/ifc-6.c |   15 +++++++++++++++
 gcc/tree-if-conv.c                    |   12 +++++++++++-
 2 files changed, 26 insertions(+), 1 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ifc-6.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ifc-6.c b/gcc/testsuite/gcc.dg/tree-ssa/ifc-6.c
new file mode 100644
index 0000000..a9c5db3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ifc-6.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-c -O2 -ftree-vectorize" { target *-*-* } } */
+
+static int x;
+foo (int n, int *A)
+{
+  int i;
+  for (i = 0; i < n; i++)
+    {
+      if (A[i])
+	x = 2;
+      if (A[i + 1])
+	x = 1;
+    }
+}
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index ac3ba93..759920c 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -278,7 +278,17 @@ add_to_predicate_list (basic_block bb, tree new_cond)
       cond = unfold_ssa_names (cond, 5);
     }
 
-  set_bb_predicate (bb, cond);
+  if (!is_gimple_condexpr (cond))
+    {
+      gimple_seq stmts;
+      cond = force_gimple_operand (cond, &stmts, true, NULL_TREE);
+      add_bb_predicate_gimplified_stmts (bb, stmts);
+    }
+
+  if (is_true_predicate (cond))
+    reset_bb_predicate (bb);
+  else
+    set_bb_predicate (bb, cond);
 }
 
 /* Add the condition COND to the previous condition PREV_COND, and add
-- 
1.7.0.4

