re PR rtl-optimization/58997 (ICE on valid code at -O3 on x86_64-linux-gnu (affecting...
authorJakub Jelinek <jakub@redhat.com>
Tue, 5 Nov 2013 19:37:51 +0000 (20:37 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 5 Nov 2013 19:37:51 +0000 (20:37 +0100)
PR rtl-optimization/58997
* loop-iv.c (iv_subreg): For IV_UNKNOWN_EXTEND, expect
get_iv_value to be in iv->mode rather than iv->extend_mode.
(iv_extend): Likewise.  Otherwise, if iv->extend != extend,
use lowpart_subreg on get_iv_value before calling simplify_gen_unary.
* loop-unswitch.c (may_unswitch_on): Make sure op[i] is in the right
mode.

* gcc.c-torture/compile/pr58997.c: New test.

From-SVN: r204413

gcc/ChangeLog
gcc/loop-iv.c
gcc/loop-unswitch.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr58997.c [new file with mode: 0644]

index 468b1856c4f883515155df47aa9c2c574b3542ef..72f93f9d07ed45761188b6366fccfe8185682e15 100644 (file)
@@ -1,3 +1,13 @@
+2013-11-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/58997
+       * loop-iv.c (iv_subreg): For IV_UNKNOWN_EXTEND, expect
+       get_iv_value to be in iv->mode rather than iv->extend_mode.
+       (iv_extend): Likewise.  Otherwise, if iv->extend != extend,
+       use lowpart_subreg on get_iv_value before calling simplify_gen_unary.
+       * loop-unswitch.c (may_unswitch_on): Make sure op[i] is in the right
+       mode.
+
 2013-11-05  Andrew MacLeod  <amacleod@redhat.com>
 
        * gimple.h: Move some prototypes to gimple-expr.h and add to include
index b9bc3348733d1bf5e08e3f1e8518049fb0f66d6a..97aa52fc6dd69b8bf9db85b6331647c9389bdf4f 100644 (file)
@@ -436,7 +436,9 @@ iv_subreg (struct rtx_iv *iv, enum machine_mode mode)
       && !iv->first_special)
     {
       rtx val = get_iv_value (iv, const0_rtx);
-      val = lowpart_subreg (mode, val, iv->extend_mode);
+      val = lowpart_subreg (mode, val,
+                           iv->extend == IV_UNKNOWN_EXTEND
+                           ? iv->mode : iv->extend_mode);
 
       iv->base = val;
       iv->extend = IV_UNKNOWN_EXTEND;
@@ -476,8 +478,14 @@ iv_extend (struct rtx_iv *iv, enum iv_extend_code extend, enum machine_mode mode
       && !iv->first_special)
     {
       rtx val = get_iv_value (iv, const0_rtx);
+      if (iv->extend_mode != iv->mode
+         && iv->extend != IV_UNKNOWN_EXTEND
+         && iv->extend != extend)
+       val = lowpart_subreg (iv->mode, val, iv->extend_mode);
       val = simplify_gen_unary (iv_extend_to_rtx_code (extend), mode,
-                               val, iv->extend_mode);
+                               val,
+                               iv->extend == extend
+                               ? iv->extend_mode : iv->mode);
       iv->base = val;
       iv->extend = IV_UNKNOWN_EXTEND;
       iv->mode = iv->extend_mode = mode;
index 3bdb10a4373f1b2a08f11bb78e24d1448f6a05b6..219c943545b11e4f478a3b3c2569ff5599027c56 100644 (file)
@@ -191,6 +191,7 @@ may_unswitch_on (basic_block bb, struct loop *loop, rtx *cinsn)
   if (!test)
     return NULL_RTX;
 
+  mode = VOIDmode;
   for (i = 0; i < 2; i++)
     {
       op[i] = XEXP (test, i);
@@ -205,11 +206,15 @@ may_unswitch_on (basic_block bb, struct loop *loop, rtx *cinsn)
        return NULL_RTX;
 
       op[i] = get_iv_value (&iv, const0_rtx);
+      if (iv.extend != IV_UNKNOWN_EXTEND
+         && iv.mode != iv.extend_mode)
+       op[i] = lowpart_subreg (iv.mode, op[i], iv.extend_mode);
+      if (mode == VOIDmode)
+       mode = iv.mode;
+      else
+       gcc_assert (mode == iv.mode);
     }
 
-  mode = GET_MODE (op[0]);
-  if (mode == VOIDmode)
-    mode = GET_MODE (op[1]);
   if (GET_MODE_CLASS (mode) == MODE_CC)
     {
       if (at != BB_END (bb))
index 61461633e59a1412127fbccd8b18cd3ccb7d4e1c..f49141a381cd8cb93ae9b7b49a34cddeb73dfc5e 100644 (file)
@@ -1,3 +1,8 @@
+2013-11-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/58997
+       * gcc.c-torture/compile/pr58997.c: New test.
+
 2013-11-05  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/58724
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr58997.c b/gcc/testsuite/gcc.c-torture/compile/pr58997.c
new file mode 100644 (file)
index 0000000..2c7a0f8
--- /dev/null
@@ -0,0 +1,19 @@
+/* PR rtl-optimization/58997 */
+
+int a, b, c, e;
+short d;
+char h;
+
+void
+foo ()
+{
+  while (b)
+    {
+      d = a ? c : 1 % a;
+      c = d;
+      h = d;
+      if (!h)
+       while (e)
+         ;
+    }
+}