On 29-01-15 18:25, Jakub Jelinek wrote:
The stdarg pass can't grok too heavy optimizations, so if at all possible,
don't schedule such passes early, and if you for some reason do, avoid
optimizing in there the va_list related accesses.

This patch work for the example.

In pass_lim1, I get:
...
;; Function gen_rtvec (gen_rtvec, funcdef_no=1, decl_uid=1841, cgraph_uid=1, symbol_order=1)

va_list_related_stmt_p: no simple_mem_ref
_15 = p.gp_offset;
va_list_related_stmt_p: no simple_mem_ref
_16 = p.reg_save_area;
va_list_related_stmt_p: no simple_mem_ref
p.gp_offset = _21;
va_list_related_stmt_p: no simple_mem_ref
_23 = p.overflow_arg_area;
va_list_related_stmt_p: no simple_mem_ref
p.overflow_arg_area = _25;
va_list_related_stmt_p: MOVE_IMPOSSIBLE
_15 = p.gp_offset;
va_list_related_stmt_p: MOVE_IMPOSSIBLE
_16 = p.reg_save_area;
va_list_related_stmt_p: MOVE_IMPOSSIBLE
_23 = p.overflow_arg_area;
gen_rtvec (int n)
...

Thanks,
- Tom
Handle va_list conservatively in pass_lim

---
 gcc/tree-ssa-loop-im.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c
index 9aba79b..2520fa2 100644
--- a/gcc/tree-ssa-loop-im.c
+++ b/gcc/tree-ssa-loop-im.c
@@ -70,6 +70,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-propagate.h"
 #include "trans-mem.h"
 #include "gimple-fold.h"
+#include "target.h"
+#include "gimple-walk.h"
 
 /* TODO:  Support for predicated code motion.  I.e.
 
@@ -289,6 +291,32 @@ enum move_pos
   };
 
 
+static tree
+va_list_related_tree_p (tree *t, int *walk_subtrees ATTRIBUTE_UNUSED,
+			void *data ATTRIBUTE_UNUSED)
+{
+  tree cfun_va_list = targetm.fn_abi_va_list (cfun->decl);
+  tree c1, c2, type;
+  if (!DECL_P (*t))
+    return NULL_TREE;
+  type = TREE_TYPE (*t);
+  c1 = TYPE_CANONICAL (type);
+  c2 = TYPE_CANONICAL(cfun_va_list);
+
+  if (c1 == c2)
+    return *t;
+
+  return NULL_TREE;
+}
+
+bool
+va_list_related_stmt_p (gimple stmt)
+{
+  gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
+  tree res = walk_gimple_stmt (&gsi, NULL, va_list_related_tree_p, NULL);
+  return res != NULL_TREE;
+}
+
 /* If it is possible to hoist the statement STMT unconditionally,
    returns MOVE_POSSIBLE.
    If it is possible to hoist the statement STMT, but we must avoid making
@@ -384,6 +412,15 @@ movement_possibility (gimple stmt)
 	}
     }
 
+  if (va_list_related_stmt_p (stmt))
+    {
+      if (dump_file)
+	{
+	  fprintf (dump_file, "va_list_related_stmt_p: MOVE_IMPOSSIBLE\n");
+	  print_gimple_stmt (dump_file, stmt, 2, 0);
+	}
+      return MOVE_IMPOSSIBLE;
+    }
   return ret;
 }
 
@@ -593,6 +630,16 @@ simple_mem_ref_in_stmt (gimple stmt, bool *is_store)
   if (!gimple_assign_single_p (stmt))
     return NULL;
 
+  if (va_list_related_stmt_p (stmt))
+    {
+      if (dump_file)
+	{
+	  fprintf (dump_file, "va_list_related_stmt_p: no simple_mem_ref\n");
+	  print_gimple_stmt (dump_file, stmt, 2, 0);
+	}
+      return NULL;
+    }
+
   lhs = gimple_assign_lhs_ptr (stmt);
   rhs = gimple_assign_rhs1_ptr (stmt);
 
-- 
1.9.1

Reply via email to