expr.c (expand_expr_real_1): Do not unnecessarily copy the object in the MEM_P case.
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 15 Oct 2012 10:48:17 +0000 (10:48 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Mon, 15 Oct 2012 10:48:17 +0000 (10:48 +0000)
* expr.c (expand_expr_real_1) <VIEW_CONVERT_EXPR>: Do not unnecessarily
copy the object in the MEM_P case.

From-SVN: r192452

gcc/ChangeLog
gcc/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/unchecked_convert9.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/unchecked_convert9.ads [new file with mode: 0644]

index 85db69e..2c7af2a 100644 (file)
@@ -1,3 +1,8 @@
+2012-10-15  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * expr.c (expand_expr_real_1) <VIEW_CONVERT_EXPR>: Do not unnecessarily
+       copy the object in the MEM_P case.
+
 2012-10-15  Richard Guenther  <rguenther@suse.de>
 
        * tree-streamer-out.c (streamer_pack_tree_bitfields): Back
@@ -37,7 +42,6 @@
        (build_insn_chain): Use df_get_live_out instead of DF_LR_OUT.
        (do_reload): Remove the DF_LIVE problem for -O1.
 
-
 2012-10-14  Steven Bosscher  <steven@gcc.gnu.org>
 
        PR rtl-optimization/54919
index 1adea93..7cf812d 100644 (file)
@@ -10270,10 +10270,15 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
        {
          enum insn_code icode;
 
-         op0 = copy_rtx (op0);
-
          if (TYPE_ALIGN_OK (type))
-           set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
+           {
+             /* ??? Copying the MEM without substantially changing it might
+                run afoul of the code handling volatile memory references in
+                store_expr, which assumes that TARGET is returned unmodified
+                if it has been used.  */
+             op0 = copy_rtx (op0);
+             set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
+           }
          else if (mode != BLKmode
                   && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode)
                   /* If the target does have special handling for unaligned
index f361e2a..23f8c2e 100644 (file)
@@ -1,3 +1,7 @@
+2012-10-15  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/unchecked_convert9.ad[sb]: New test.
+
 2012-10-13  Jason Merrill  <jason@redhat.com>
 
        * g++.dg/tls/thread_local7g.C: Require tls_native.
diff --git a/gcc/testsuite/gnat.dg/unchecked_convert9.adb b/gcc/testsuite/gnat.dg/unchecked_convert9.adb
new file mode 100644 (file)
index 0000000..133f3b9
--- /dev/null
@@ -0,0 +1,15 @@
+-- { dg-do compile }
+-- { dg-options "-O -fdump-rtl-final" }
+
+package body Unchecked_Convert9 is
+
+   procedure Proc is
+     L : Unsigned_32 := 16#55557777#;
+   begin
+     Var := Conv (L);
+   end;
+
+end Unchecked_Convert9;
+
+-- { dg-final { scan-rtl-dump-times "set \\(mem/v" 1 "final" } }
+-- { dg-final { cleanup-rtl-dump "final" } }
diff --git a/gcc/testsuite/gnat.dg/unchecked_convert9.ads b/gcc/testsuite/gnat.dg/unchecked_convert9.ads
new file mode 100644 (file)
index 0000000..d4595f5
--- /dev/null
@@ -0,0 +1,20 @@
+with System;
+with Ada.Unchecked_Conversion;
+with Interfaces; use Interfaces;
+
+package Unchecked_Convert9 is
+
+   type R is record
+     H : Unsigned_16;
+     L : Unsigned_16;
+   end record;
+
+   Var : R;
+   pragma Volatile (Var);
+
+   function Conv is new
+     Ada.Unchecked_Conversion (Source => Unsigned_32, Target => R);
+
+   procedure Proc;
+
+end Unchecked_Convert9;