The following avoids to increase hard register lifetime by not
sinking loads from those.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

I wonder if it would make sense to not treat hardregs as
memory but instead rewrite them into SSA form but with
SSA_NAME_OCCURS_IN_ABNORMAL_PHI set (which really tells
that all SSA names of the underlying decl must be able
to coalesce to the same register).

Richard.

2014-06-24  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/61572
        * tree-ssa-sink.c (statement_sink_location): Do not sink
        loads from hard registers.

        * gcc.target/i386/pr61572.c: New testcase.

Index: gcc/tree-ssa-sink.c
===================================================================
--- gcc/tree-ssa-sink.c (revision 211928)
+++ gcc/tree-ssa-sink.c (working copy)
@@ -374,6 +374,12 @@ statement_sink_location (gimple stmt, ba
         nearest to commondom.  */
       if (gimple_vuse (stmt))
        {
+         /* Do not sink loads from hard registers.  */
+         if (gimple_assign_single_p (stmt)
+             && TREE_CODE (gimple_assign_rhs1 (stmt)) == VAR_DECL
+             && DECL_HARD_REGISTER (gimple_assign_rhs1 (stmt)))
+           return false;
+
          imm_use_iterator imm_iter;
          use_operand_p use_p;
          basic_block found = NULL;
Index: gcc/testsuite/gcc.target/i386/pr61572.c
===================================================================
--- gcc/testsuite/gcc.target/i386/pr61572.c     (revision 0)
+++ gcc/testsuite/gcc.target/i386/pr61572.c     (working copy)
@@ -0,0 +1,46 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+struct autofs_sb_info
+{
+  int exp_timeout;
+};
+void *f;
+int g;
+static int fn1 (struct autofs_sb_info *p1)
+{
+  int a, b;
+  a = (
+       {
+       register __typeof__(0) c
+#if defined __x86_64__
+       asm("rdx")
+#endif
+       ;
+       b = c;
+       int d;
+       __typeof__(0) e;
+       e = p1->exp_timeout / 1000;
+       switch (0)
+       default:
+       asm("" : "=a"(d) : "0"(e), ""(0));
+       d;
+       });
+  if (a)
+    return 1;
+  if (b)
+    p1->exp_timeout = 0;
+  return 0;
+}
+
+int fn2 ()
+{
+  struct autofs_sb_info *h = f;
+  switch (g)
+    {
+      case 0 ?:
+0 : return fn1 (h);
+      default:
+    return 0;
+    }
+}

Reply via email to