The VIEW_CONVERT_EXPR expansion path fails to handle the case where
we promote alignment for !STRICT_ALIGNMENT targets but for modes
that are supposed to be handled by movmisalign.

This is exposed in gcc.dg/torture/pr45678-2.c on i?86 when
you apply the candidate patch for PR50444 in comment #15.

I'm now bootstrapping and regtesting this as a prerequesite.

Richard.

2012-01-23  Richard Guenther  <rguent...@suse.de>

        PR tree-optimization/50444
        * expr.c (expand_expr_real_1): Properly expand VIEW_CONVERT_EXPR
        to an aligned mode from unaligned memory using movmisalign.

Index: gcc/expr.c
===================================================================
--- gcc/expr.c  (revision 183423)
+++ gcc/expr.c  (working copy)
@@ -10044,10 +10044,24 @@ expand_expr_real_1 (tree exp, rtx target
         results.  */
       if (MEM_P (op0))
        {
+         enum insn_code icode;
+
          op0 = copy_rtx (op0);
 
          if (TYPE_ALIGN_OK (type))
            set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
+         else if (mode != BLKmode
+                  && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode)
+                  && ((icode = optab_handler (movmisalign_optab, mode))
+                      != CODE_FOR_nothing))
+           {
+             struct expand_operand ops[2];
+             PUT_MODE (op0, mode);
+             create_output_operand (&ops[0], NULL_RTX, mode);
+             create_fixed_operand (&ops[1], op0);
+             expand_insn (icode, 2, ops);
+             return ops[0].value;
+           }
          else if (STRICT_ALIGNMENT
                   && mode != BLKmode
                   && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode))

Reply via email to