re PR middle-end/82875 (ICE at -Os on valid code on x86_64-linux-gnu: in find_widenin...
authorJakub Jelinek <jakub@redhat.com>
Wed, 22 Nov 2017 09:57:28 +0000 (10:57 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 22 Nov 2017 09:57:28 +0000 (10:57 +0100)
PR middle-end/82875
* optabs.c (expand_doubleword_mult, expand_binop): Before calling
expand_binop with *mul_widen_optab, make sure at least one of the
operands doesn't have VOIDmode.

* gcc.dg/pr82875.c: New test.
* gcc.c-torture/compile/pr82875.c: New test.

From-SVN: r255050

gcc/ChangeLog
gcc/optabs.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr82875.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr82875.c [new file with mode: 0644]

index d4b184e12626a94748adb256ca02e1be4f272b67..ace7c7c0ce75e17453285c49cd193103e3fc56e1 100644 (file)
@@ -1,5 +1,10 @@
 2017-11-22  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/82875
+       * optabs.c (expand_doubleword_mult, expand_binop): Before calling
+       expand_binop with *mul_widen_optab, make sure at least one of the
+       operands doesn't have VOIDmode.
+
        PR debug/83034
        * dwarf2out.c (mem_loc_descriptor): Handle VEC_SERIES.
 
index 847b801d288932412c7d8ed644b935d55ddbae21..518ce7a972cfaa7593d44252856cf422afc6fa1f 100644 (file)
@@ -861,6 +861,11 @@ expand_doubleword_mult (machine_mode mode, rtx op0, rtx op1, rtx target,
   if (target && !REG_P (target))
     target = NULL_RTX;
 
+  /* *_widen_optab needs to determine operand mode, make sure at least
+     one operand has non-VOID mode.  */
+  if (GET_MODE (op0_low) == VOIDmode && GET_MODE (op1_low) == VOIDmode)
+    op0_low = force_reg (word_mode, op0_low);
+
   if (umulp)
     product = expand_binop (mode, umul_widen_optab, op0_low, op1_low,
                            target, 1, OPTAB_DIRECT);
@@ -1199,6 +1204,10 @@ expand_binop (machine_mode mode, optab binoptab, rtx op0, rtx op1,
                                  : smul_widen_optab),
                                 wider_mode, mode) != CODE_FOR_nothing))
     {
+      /* *_widen_optab needs to determine operand mode, make sure at least
+        one operand has non-VOID mode.  */
+      if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
+       op0 = force_reg (mode, op0);
       temp = expand_binop (wider_mode,
                           unsignedp ? umul_widen_optab : smul_widen_optab,
                           op0, op1, NULL_RTX, unsignedp, OPTAB_DIRECT);
index b08855f9566911409b533926f160dda323295541..b7e0c470c4c765a0938b0b5a2343c8fe4cdddf63 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/82875
+       * gcc.dg/pr82875.c: New test.
+       * gcc.c-torture/compile/pr82875.c: New test.
+
 2017-11-22  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/83034
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr82875.c b/gcc/testsuite/gcc.c-torture/compile/pr82875.c
new file mode 100644 (file)
index 0000000..4360ebc
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR middle-end/82875 */
+
+signed char a;
+unsigned b;
+long c, d;
+long long e;
+
+void
+foo (void)
+{
+  short f = a = 6;
+  while (0)
+    while (a <= 7)
+      {
+       for (;;)
+         ;
+       lab:
+         while (c <= 73)
+           ;
+       e = 20;
+       d ? (a %= c) * (e *= a ? f : b) : 0;
+      }
+  goto lab;
+}
diff --git a/gcc/testsuite/gcc.dg/pr82875.c b/gcc/testsuite/gcc.dg/pr82875.c
new file mode 100644 (file)
index 0000000..5b97b80
--- /dev/null
@@ -0,0 +1,11 @@
+/* PR middle-end/82875 */
+/* { dg-do compile } */
+/* { dg-options "-ftree-ter" } */
+
+const int a = 100;
+
+void
+foo (void)
+{
+  int c[a];
+}