OSDN Git Service

PR rtl-optimization/56494
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 5 Mar 2013 06:04:14 +0000 (06:04 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 5 Mar 2013 06:04:14 +0000 (06:04 +0000)
* simplify-rtx.c (simplify_truncation): If C is narrower than A,
optimize (truncate:A (subreg:B (truncate:C X) 0)) into
(subreg:A (truncate:C X) 0) instead of (truncate:A X).

* gcc.dg/pr56494.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@196451 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/simplify-rtx.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr56494.c [new file with mode: 0644]

index 3abc676..2678b16 100644 (file)
@@ -1,5 +1,10 @@
 2013-03-05  Jakub Jelinek  <jakub@redhat.com>
 
+       PR rtl-optimization/56494
+       * simplify-rtx.c (simplify_truncation): If C is narrower than A,
+       optimize (truncate:A (subreg:B (truncate:C X) 0)) into
+       (subreg:A (truncate:C X) 0) instead of (truncate:A X).
+
        PR middle-end/56461
        * sel-sched-ir.c (free_sched_pools): Release
        succs_info_pool.stack[succs_info_pool.max_top] vectors too
index 3f04b8b..43700cf 100644 (file)
@@ -757,8 +757,17 @@ simplify_truncation (enum machine_mode mode, rtx op,
       && SCALAR_INT_MODE_P (GET_MODE (SUBREG_REG (op)))
       && GET_CODE (SUBREG_REG (op)) == TRUNCATE
       && subreg_lowpart_p (op))
-    return simplify_gen_unary (TRUNCATE, mode, XEXP (SUBREG_REG (op), 0),
-                              GET_MODE (XEXP (SUBREG_REG (op), 0)));
+    {
+      rtx inner = XEXP (SUBREG_REG (op), 0);
+      if (GET_MODE_PRECISION (mode)
+         <= GET_MODE_PRECISION (GET_MODE (SUBREG_REG (op))))
+       return simplify_gen_unary (TRUNCATE, mode, inner, GET_MODE (inner));
+      else
+       /* If subreg above is paradoxical and C is narrower
+          than A, return (subreg:A (truncate:C X) 0).  */
+       return simplify_gen_subreg (mode, SUBREG_REG (op),
+                                   GET_MODE (SUBREG_REG (op)), 0);
+    }
 
   /* (truncate:A (truncate:B X)) is (truncate:A X).  */
   if (GET_CODE (op) == TRUNCATE)
index 19c64d6..4529bcf 100644 (file)
@@ -1,3 +1,8 @@
+2013-03-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/56494
+       * gcc.dg/pr56494.c: New test.
+
 2013-01-04  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc.dg/pr56424.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pr56494.c b/gcc/testsuite/gcc.dg/pr56494.c
new file mode 100644 (file)
index 0000000..e73d674
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR rtl-optimization/56494 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftracer -w" } */
+
+char a;
+short b;
+void bar (int);
+
+void
+foo (void)
+{
+  bar ((!!b ? : (a *= a / 0)) >= (a = b));
+}