2014-06-03 Christian Bruel <christian.bruel@st.com>
PR tree-optimization/43934
* tree-ssa-loop-im.c (determine_max_movement): Add PHI def constant cost.
2014-06-03 Christian Bruel <christian.bruel@st.com>
PR tree-optimization/43934
* gcc.dg/tree-ssa/ssa-lim-8.c: New testcase.
===================================================================
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-lim1-details" } */
+
+void bar (int);
+void foo (int n, int m)
+{
+ unsigned i;
+ for (i = 0; i < n; ++i)
+ {
+ int x;
+ if (m < 0)
+ x = 1;
+ else
+ x = m;
+ bar (x);
+ }
+}
+
+/* { dg-final { scan-tree-dump-times "Moving PHI node" 1 "lim1" } } */
+/* { dg-final { cleanup-tree-dump "lim1" } } */
===================================================================
@@ -719,8 +719,21 @@ determine_max_movement (gimple stmt, bool must_pre
FOR_EACH_PHI_ARG (use_p, stmt, iter, SSA_OP_USE)
{
val = USE_FROM_PTR (use_p);
+
if (TREE_CODE (val) != SSA_NAME)
- continue;
+ {
+ unsigned cst_cost = 1;
+
+ gcc_assert (TREE_CODE (val) == INTEGER_CST
+ || TREE_CODE (val) == REAL_CST
+ || TREE_CODE (val) == VECTOR_CST
+ || TREE_CODE (val) == COMPLEX_CST
+ || TREE_CODE (val) == ADDR_EXPR);
+
+ min_cost = MIN (min_cost, cst_cost);
+ total_cost += cst_cost;
+ continue;
+ }
if (!add_dependency (val, lim_data, loop, false))
return false;
def_data = get_lim_data (SSA_NAME_DEF_STMT (val));