]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR rtl-optimization/56494 (ICE in simplify_truncation, at simplify-rtx.c:619)
authorJakub Jelinek <jakub@redhat.com>
Tue, 5 Mar 2013 06:04:14 +0000 (07:04 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 5 Mar 2013 06:04:14 +0000 (07:04 +0100)
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).

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

From-SVN: r196451

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

index 3abc676ec517f974b2f1f5fecaecb7e2974c494a..2678b16fb8bbec3f151c25e745ab53178616849d 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 3f04b8bdeb3c0114a55cfd359f9566bb805643ce..43700cff1518f04d98d13114142a8ff47f08dbf2 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 19c64d61f64e5e91d57a6354a23593bfcc8676bd..4529bcfc8bf578011e353d682459174694aa033d 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));
+}