Use strict_low_part for loading a constant only if it is cheaper
authorAndreas Schwab <schwab@suse.de>
Wed, 18 Jun 2014 10:37:14 +0000 (10:37 +0000)
committerAndreas Schwab <schwab@gcc.gnu.org>
Wed, 18 Jun 2014 10:37:14 +0000 (10:37 +0000)
PR rtl-optimization/54555
* postreload.c (move2add_use_add2_insn): Substitute
STRICT_LOW_PART only if it is cheaper.

testsuite/:
PR rtl-optimization/54555
* gcc.target/m68k/pr54555.c: New test.

From-SVN: r211777

gcc/ChangeLog
gcc/postreload.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/m68k/pr54555.c [new file with mode: 0644]

index 2089dec9e2f71f57dddeb0d6153574742aa547f5..562aeaecf4f9eb1d1cb2913ca89883cf9f818e02 100644 (file)
@@ -1,3 +1,9 @@
+2014-06-18  Andreas Schwab  <schwab@suse.de>
+
+       PR rtl-optimization/54555
+       * postreload.c (move2add_use_add2_insn): Substitute
+       STRICT_LOW_PART only if it is cheaper.
+
 2014-06-18  Uros Bizjak  <ubizjak@gmail.com>
 
        * config/i386/i386.md (*sibcall_memory): Rename from *sibcall_intern.
index 9d716498be48462d410cbe0ade87b78a833b8420..89f0c8460e2c20bc79f0795a64d242d9c76293f1 100644 (file)
@@ -1805,10 +1805,14 @@ move2add_use_add2_insn (rtx reg, rtx sym, rtx off, rtx insn)
                                   gen_rtx_STRICT_LOW_PART (VOIDmode,
                                                            narrow_reg),
                                   narrow_src);
-                 changed = validate_change (insn, &PATTERN (insn),
-                                            new_set, 0);
-                 if (changed)
-                   break;
+                 get_full_set_rtx_cost (new_set, &newcst);
+                 if (costs_lt_p (&newcst, &oldcst, speed))
+                   {
+                     changed = validate_change (insn, &PATTERN (insn),
+                                                new_set, 0);
+                     if (changed)
+                       break;
+                   }
                }
            }
        }
index c61da63182f7a1128448373a3b3922b50a463ca4..3be9d2e6860c86fe3e8a506135537fc30f284429 100644 (file)
@@ -1,3 +1,8 @@
+2014-06-18  Andreas Schwab  <schwab@suse.de>
+
+       PR rtl-optimization/54555
+       * gcc.target/m68k/pr54555.c: New test.
+
 2014-06-18  Olivier Hainque  <hainque@adacore.com>
 
        * gnat.dg/blocklocs.adb: New test.
diff --git a/gcc/testsuite/gcc.target/m68k/pr54555.c b/gcc/testsuite/gcc.target/m68k/pr54555.c
new file mode 100644 (file)
index 0000000..4be704b
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR rtl-optimization/54555
+   Test that postreload does not shorten the load of small constants to
+   use move.b instead of moveq.  */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-final { scan-assembler-not "move\\.?b" } } */
+
+void foo (void);
+void bar (int a)
+{
+  if (a == 16 || a == 23) foo ();
+  if (a == -110 || a == -128) foo ();
+}