Bug 90756 - [7/8 Regression] g++ ICE in convert_move, at expr.c:218 on i686 and s390x
Summary: [7/8 Regression] g++ ICE in convert_move, at expr.c:218 on i686 and s390x
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 7.5
Assignee: Jakub Jelinek
URL:
Keywords: ice-on-valid-code
: 90327 91042 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-06-05 12:58 UTC by Matthias Klose
Modified: 2019-08-30 13:32 UTC (History)
8 users (show)

See Also:
Host:
Target: i686-linux-gnu, s390x-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-07-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2019-06-05 12:58:57 UTC
[forwarded from https://bugs.debian.org/930012]

this might be the same as PR90327, but here it is seen on the gcc-8 branch as well, both i686 and s390x. seen building firefox 68.0~b6-2 on i686 and s390x.

$ g++ -c -O1 -fPIC -Wall -Wno-narrowing -Wno-psabi skcms.ii 
during RTL pass: expand
skcms.ii: In function 'void ck()':
skcms.ii:65:6: internal compiler error: in convert_move, at expr.c:218
 void ck() {
      ^~
Please submit a full bug report,
with preprocessed source if appropriate.

$ cat skcms.ii
typedef enum {
  a,
  c,
  d,
  e,
  f,
  g,
  h,
  i,
  j,
  k,
  l,
  ah,
  ai,
  aj,
  ak,
  al,
  am,
  an,
  ao,
  ap,
  aq,
  ar,
  as,
  at,
  au,
  av,
  aw,
  ax,
  ay,
  az,
  ba,
  bb,
  bc,
  bd,
  be,
  bf,
  bg,
  bh,
  bj,
  bk,
  bl,
  bm,
  bn,
  bo,
  m,
  bp,
  bq,
  br,
  bs
} bt;
template <int bi, typename bu> struct p {
  typedef bu __attribute__((vector_size(bi * sizeof(bu)))) bw;
};
template <int bi, typename bu> using bx = typename p<bi, bu>::bw;
using by = bx<4, float>;
using bz = bx<4, unsigned long long>;
using ca = bx<4, short>;
by cb;
template <typename bu, typename cc> void cd(cc, bu);
template <typename ce, typename cf> ce cast(cf);
ca cg(by);
template <typename bu, typename cc> bu ch(cc);
bt ci;
void ck() {
  by n = cb, b = cb;
  while (true)
    switch (ci) {
    case a:
    case c:
    case e:
    case f:
    case g:
    case h:
    case d:
    case i:
    case j:
    case k:
    case l:
    case ah:
    case ai:
    case aj:
    case ak:
    case al:
      n = ch<by>(c);
    case am: {
      by o = n;
      n = b;
      b = o;
    }
    case an:
    case ao:
    case ap:
    case aq:
    case ar:
    case as:
    case at:
    case au:
    case av:
    case aw:
    case ax:
    case ay:
    case az:
    case ba:
    case bb:
    case bc:
    case bd:
    case be:
    case bf:
    case bg:
    case bh:
    case bj:
    case bk:
    case bl:
    case bm:
    case bn:
    case bo:
    case m:
    case bp:
    case bq: {
      ca cm = cg(b);
      __attribute__((__vector_size__(
          4 * sizeof(long long)))) unsigned long long cn = cast<bz>(cm);
      cd(ck, cn);
    }
    case br:
    case bs:;
    }
}
Comment 1 Matthias Klose 2019-06-05 13:00:41 UTC
not a regression, seen with 6 and 7 as well.
Comment 2 Matthias Klose 2019-06-14 07:23:52 UTC
seen on trunk 20190527 as well.
Comment 3 Mike Hommey 2019-06-25 04:13:00 UTC
This also happens on mips and mipsel. Here's a further reduced version, courtesy of creduce:

typedef enum { a, c } d;
template <int e, typename f> struct g {
  typedef f __attribute__((vector_size(e * sizeof(int)))) h;
};
template <int e, typename f> using i = typename g<e, f>::h;
using j = i<4, float>;
using k = i<4, short>;
template <typename, typename l> void cast(l);
d m;
void n() {
  j o, b;
  while (true)
    switch (m) {
    case a: {
      j p = o;
      o = b;
      b = p;
    }
    case c:
      cast<k>(b);
    }
}
Comment 4 Mike Hommey 2019-06-25 04:13:56 UTC
Also note it does *not* happen on i686 when SSE is enabled.
Comment 5 Jakub Jelinek 2019-06-26 10:28:53 UTC
The r228175
        (promote_ssa_mode): Disregard BLKmode from promote_decl, and                                                                               
        bypass TYPE_MODE to get the actual vector mode.                                                                                            

+  /* Bypass TYPE_MODE when it maps vector modes to BLKmode.  */                                                                                   
+  if (mode == BLKmode)                                                                                                                            
+    {                                                                                                                                             
+      gcc_assert (VECTOR_TYPE_P (type));                                                                                                          
+      mode = type->type_common.mode;                                                                                                              
+    }                                                                                                                                             
+                                                                                                                                                  

change looks highly suspicious, that introduces in the IL vector modes that aren't really supported.  If that was done because some SSA_NAMEs might have underlying decl that has DECL_MODE, I'd say we should either treat all DECL_MODE similarly to TYPE_MODE, or add more hacks where for vector type decls we just ignore DECL_MODE and use corresponding TYPE_MODE (I think we have quite a few of those already).
Comment 6 Jakub Jelinek 2019-06-26 10:47:42 UTC
Hand reduced:
template <int N, typename T> struct A {
  typedef T __attribute__((vector_size(N * sizeof(T)))) a;
};
template <int N, typename T> using U = typename A<N, T>::a;
using B = U<4, float>;
using C = U<4, unsigned long long>;
using D = U<4, short>;
B z;
template <typename T, typename U> void foo (U, T);
template <typename T, typename U> T bar (U);
D y(B);
template <typename T, typename U> T baz (U);
int x;

void
qux ()
{
  B n = z, b = z;
  while (true)
    switch (x)
      {
      case 0 ... 15: n = baz<B> (1);
      case 16: { B o = n; n = b; b = o; }
      case 17 ... 46: { D u = y(b); C v = bar<C> (u); foo (qux, v); }
      }
}
Comment 7 Richard Biener 2019-06-26 10:48:43 UTC
(In reply to Jakub Jelinek from comment #5)
> The r228175
>         (promote_ssa_mode): Disregard BLKmode from promote_decl, and        
> 
>         bypass TYPE_MODE to get the actual vector mode.                     
> 
> 
> +  /* Bypass TYPE_MODE when it maps vector modes to BLKmode.  */            
> 
> +  if (mode == BLKmode)                                                     
> 
> +    {                                                                      
> 
> +      gcc_assert (VECTOR_TYPE_P (type));                                   
> 
> +      mode = type->type_common.mode;                                       
> 
> +    }                                                                      
> 
> +                                                                           
> 
> 
> change looks highly suspicious, that introduces in the IL vector modes that
> aren't really supported.  If that was done because some SSA_NAMEs might have
> underlying decl that has DECL_MODE, I'd say we should either treat all
> DECL_MODE similarly to TYPE_MODE, or add more hacks where for vector type
> decls we just ignore DECL_MODE and use corresponding TYPE_MODE (I think we
> have quite a few of those already).

Indeed.  We probably need to differentiate callers of promote_ssa_mode.
Like the one in get_temp_reg seems to deal with BLKmode but AFAICS
promote_ssa_mode will never return BLKmode itself?  Thus

Index: gcc/tree-outof-ssa.c
===================================================================
--- gcc/tree-outof-ssa.c        (revision 272616)
+++ gcc/tree-outof-ssa.c        (working copy)
@@ -652,9 +652,10 @@ get_temp_reg (tree name)
 {
   tree type = TREE_TYPE (name);
   int unsignedp;
-  machine_mode reg_mode = promote_ssa_mode (name, &unsignedp);
-  if (reg_mode == BLKmode)
+  if (TYPE_MODE (type) == BLKmode)
     return assign_temp (type, 0, 0);
+  machine_mode reg_mode = promote_ssa_mode (name, &unsignedp);
+  gcc_assert (reg_mode != BLKmode);
   rtx x = gen_reg_rtx (reg_mode);
   if (POINTER_TYPE_P (type))
     mark_reg_pointer (x, TYPE_ALIGN (TREE_TYPE (type)));

the original change may have been motivated by ABI boundary issues
of caller/callee mismatching in what ISA they support despite having
arguments whose ABI depend on that?
Comment 8 Jakub Jelinek 2019-06-27 06:27:45 UTC
--- gcc/explow.c.jj	2019-01-02 00:12:16.863028945 +0100
+++ gcc/explow.c	2019-06-26 23:27:06.318478614 +0200
@@ -895,7 +895,7 @@ promote_ssa_mode (const_tree name, int *
   machine_mode mode = TYPE_MODE (type);
 
   /* Bypass TYPE_MODE when it maps vector modes to BLKmode.  */
-  if (mode == BLKmode)
+  if (0 && mode == BLKmode)
     {
       gcc_assert (VECTOR_TYPE_P (type));
       mode = type->type_common.mode;
passed bootstrap/regtest on x86_64-linux and i686-linux and fixes the testcase too.
Comment 9 Jakub Jelinek 2019-07-03 07:31:58 UTC
*** Bug 91042 has been marked as a duplicate of this bug. ***
Comment 10 Jakub Jelinek 2019-07-03 07:49:36 UTC
*** Bug 90327 has been marked as a duplicate of this bug. ***
Comment 11 Jakub Jelinek 2019-07-03 07:51:02 UTC
Some of the dups are marked as regressions.
Comment 12 Jakub Jelinek 2019-07-04 04:49:54 UTC
Author: jakub
Date: Thu Jul  4 04:49:22 2019
New Revision: 273036

URL: https://gcc.gnu.org/viewcvs?rev=273036&root=gcc&view=rev
Log:
	PR rtl-optimization/90756
	* explow.c (promote_ssa_mode): Always use TYPE_MODE, don't bypass it
	for VECTOR_TYPE_P.

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

Added:
    trunk/gcc/testsuite/gcc.dg/pr90756.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/explow.c
    trunk/gcc/testsuite/ChangeLog
Comment 13 Jakub Jelinek 2019-07-04 08:05:38 UTC
Should be fixed on the trunk so far.
Comment 14 Mike Hommey 2019-07-04 10:07:59 UTC
If I apply the patch on 6.4, I'm getting a different ICE:

internal compiler error: in emit_block_move_hints, at expr.c:1099
[task 2019-07-04T09:48:09.107Z] 09:48:09     INFO -   static void exec_ops(const Op* ops, const void** args,
[task 2019-07-04T09:48:09.107Z] 09:48:09     INFO -               ^~~~~~~~
[task 2019-07-04T09:48:09.107Z] 09:48:09     INFO -  0x8d20b5 emit_block_move_hints(rtx_def*, rtx_def*, rtx_def*, block_op_methods, unsigned int, long, unsigned long, unsigned long, unsigned long)
[task 2019-07-04T09:48:09.107Z] 09:48:09     INFO -  ../../gcc-6.4.0/gcc/expr.c:1099
[task 2019-07-04T09:48:09.108Z] 09:48:09     INFO -  0x8d210f emit_block_move(rtx_def*, rtx_def*, rtx_def*, block_op_methods)
[task 2019-07-04T09:48:09.108Z] 09:48:09     INFO -  ../../gcc-6.4.0/gcc/expr.c:1158
[task 2019-07-04T09:48:09.108Z] 09:48:09     INFO -  0xbad521 emit_partition_copy
[task 2019-07-04T09:48:09.108Z] 09:48:09     INFO -  ../../gcc-6.4.0/gcc/tree-outof-ssa.c:220
[task 2019-07-04T09:48:09.108Z] 09:48:09     INFO -  0xbad521 insert_part_to_rtx_on_edge
[task 2019-07-04T09:48:09.108Z] 09:48:09     INFO -  ../../gcc-6.4.0/gcc/tree-outof-ssa.c:388
[task 2019-07-04T09:48:09.108Z] 09:48:09     INFO -  0xbad521 elim_create
[task 2019-07-04T09:48:09.108Z] 09:48:09     INFO -  ../../gcc-6.4.0/gcc/tree-outof-ssa.c:702
[task 2019-07-04T09:48:09.108Z] 09:48:09     INFO -  0xbad521 eliminate_phi
[task 2019-07-04T09:48:09.108Z] 09:48:09     INFO -  ../../gcc-6.4.0/gcc/tree-outof-ssa.c:760
[task 2019-07-04T09:48:09.108Z] 09:48:09     INFO -  0xbad521 expand_phi_nodes(ssaexpand*)
[task 2019-07-04T09:48:09.108Z] 09:48:09     INFO -  ../../gcc-6.4.0/gcc/tree-outof-ssa.c:937
[task 2019-07-04T09:48:09.109Z] 09:48:09     INFO -  0x7fedb9 execute
[task 2019-07-04T09:48:09.109Z] 09:48:09     INFO -  ../../gcc-6.4.0/gcc/cfgexpand.c:6317
Comment 15 Jakub Jelinek 2019-07-04 10:19:11 UTC
6.x isn't supported, you are on your own.
That said, possible related changes that I remember include e.g. PR90139 and PR78643.
Comment 16 Mike Hommey 2019-07-04 12:56:49 UTC
Similar ICE with 7.3.
Comment 17 Mike Hommey 2019-07-04 22:44:52 UTC
(In reply to Mike Hommey from comment #16)
> Similar ICE with 7.3.

And 7.4 (and to be clear, this is similar ICE as comment 14)
Comment 18 Mike Hommey 2019-07-06 22:51:37 UTC
And similar ICE as comment 14 with 8.3 too.

9.1 works with the patch.
Comment 19 Mike Hommey 2019-07-07 06:18:17 UTC
Applying the patch from PR90139 and this one works fixes the ICEs on this file with both GCC 7 and 8.
Comment 20 Mike Hommey 2019-07-11 10:11:18 UTC
Note this also affects mips and presumably mips64 (except for the latter, the code has a ifdef that disables inlining presumably because of this ICE)
Comment 21 Jakub Jelinek 2019-07-14 08:27:44 UTC
Author: jakub
Date: Sun Jul 14 08:27:12 2019
New Revision: 273476

URL: https://gcc.gnu.org/viewcvs?rev=273476&root=gcc&view=rev
Log:
	Backported from mainline
	2019-07-04  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/90756
	* explow.c (promote_ssa_mode): Always use TYPE_MODE, don't bypass it
	for VECTOR_TYPE_P.

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

Added:
    branches/gcc-9-branch/gcc/testsuite/gcc.dg/pr90756.c
Modified:
    branches/gcc-9-branch/gcc/ChangeLog
    branches/gcc-9-branch/gcc/explow.c
    branches/gcc-9-branch/gcc/testsuite/ChangeLog
Comment 22 Mike Hommey 2019-07-14 09:02:33 UTC
For the record, this also affects ppc64.
Comment 23 Jakub Jelinek 2019-08-29 15:04:51 UTC
Author: jakub
Date: Thu Aug 29 15:04:19 2019
New Revision: 275044

URL: https://gcc.gnu.org/viewcvs?rev=275044&root=gcc&view=rev
Log:
	Backported from mainline
	2019-07-04  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/90756
	* explow.c (promote_ssa_mode): Always use TYPE_MODE, don't bypass it
	for VECTOR_TYPE_P.

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

Added:
    branches/gcc-8-branch/gcc/testsuite/gcc.dg/pr90756.c
Modified:
    branches/gcc-8-branch/gcc/ChangeLog
    branches/gcc-8-branch/gcc/explow.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 24 Jakub Jelinek 2019-08-30 12:48:51 UTC
Author: jakub
Date: Fri Aug 30 12:48:18 2019
New Revision: 275162

URL: https://gcc.gnu.org/viewcvs?rev=275162&root=gcc&view=rev
Log:
	Backported from mainline
	2019-07-04  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/90756
	* explow.c (promote_ssa_mode): Always use TYPE_MODE, don't bypass it
	for VECTOR_TYPE_P.

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

Added:
    branches/gcc-7-branch/gcc/testsuite/gcc.dg/pr90756.c
Modified:
    branches/gcc-7-branch/gcc/ChangeLog
    branches/gcc-7-branch/gcc/explow.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 25 Jakub Jelinek 2019-08-30 13:32:09 UTC
Fixed.