Hi!

As discussed in the PR, if a var isn't addressable and has gimple reg type,
I don't see any point to honor it's DECL_ALIGN, we only refer to the
var through SSA_NAME_VAR of SSA_NAMEs, nothing is allocated on the stack
immediately and the SSA_NAMEs are turned into pseudos for which we only care
about their modes and corresponding alignments if they need to be spilled to
stack.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2014-01-09  Jakub Jelinek  <ja...@redhat.com>

        PR middle-end/47735
        * cfgexpand.c (expand_one_var): For SSA_NAMEs, if the underlying
        var satisfies use_register_for_decl, just take into account type
        alignment, rather than decl alignment.

        * gcc.target/i386/pr47735.c: New test.

--- gcc/cfgexpand.c.jj  2014-01-08 19:37:33.630986939 +0100
+++ gcc/cfgexpand.c     2014-01-09 13:38:45.073324129 +0100
@@ -1215,8 +1215,11 @@ expand_one_var (tree var, bool toplevel,
         we conservatively assume it will be on stack even if VAR is
         eventually put into register after RA pass.  For non-automatic
         variables, which won't be on stack, we collect alignment of
-        type and ignore user specified alignment.  */
-      if (TREE_STATIC (var) || DECL_EXTERNAL (var))
+        type and ignore user specified alignment.  Similarly for
+        SSA_NAMEs for which use_register_for_decl returns true.  */
+      if (TREE_STATIC (var)
+         || DECL_EXTERNAL (var)
+         || (TREE_CODE (origvar) == SSA_NAME && use_register_for_decl (var)))
        align = MINIMUM_ALIGNMENT (TREE_TYPE (var),
                                   TYPE_MODE (TREE_TYPE (var)),
                                   TYPE_ALIGN (TREE_TYPE (var)));
--- gcc/testsuite/gcc.target/i386/pr47735.c.jj  2014-01-09 13:30:14.410941107 
+0100
+++ gcc/testsuite/gcc.target/i386/pr47735.c     2014-01-09 13:28:45.000000000 
+0100
@@ -0,0 +1,16 @@
+/* PR middle-end/47735 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fomit-frame-pointer" } */
+
+unsigned
+mulh (unsigned a, unsigned b)
+{
+  unsigned long long l __attribute__ ((aligned (32)))
+    = ((unsigned long long) a * (unsigned long long) b) >> 32;
+  return l;
+}
+
+/* No need to dynamically realign the stack here.  */
+/* { dg-final { scan-assembler-not "and\[^\n\r]*%\[re\]sp" } } */
+/* Nor use a frame pointer.  */
+/* { dg-final { scan-assembler-not "%\[re\]bp" } } */

        Jakub

Reply via email to