public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/104140] New: [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e
@ 2022-01-20  7:10 belyshev at depni dot sinp.msu.ru
  2022-01-20  8:03 ` [Bug middle-end/104140] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: belyshev at depni dot sinp.msu.ru @ 2022-01-20  7:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104140

            Bug ID: 104140
           Summary: [12 Regression] ICE verify_gimple failed: type
                    mismatch in binary expression since
                    r12-6434-g0752c75536e
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: belyshev at depni dot sinp.msu.ru
  Target Milestone: ---

$ cat bug.c

int x;
unsigned u, v;
void f (void)
{
  long long y = x;
  u = y * v >> 32;
}
void g (void) { f (); }

$ gcc bug.c -S -O2 -march=rv32im -mabi=ilp32  # or: -march=rv32g -mabi=ilp32d
bug.c: In function 'g':
bug.c:8:6: error: type mismatch in binary expression
    8 | void g (void) { f (); }
      |      ^
int

int

unsigned int

highparttmp_10 = x.0_2 h* v.1_4;
during GIMPLE pass: widening_mul
bug.c:8:6: internal compiler error: verify_gimple failed
...

Found during bootstrap on riscv32 when compiling attribs.c.
Bisected to r12-6434-g0752c75536e:

Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Tue Jan 11 12:30:44 2022 +0000

    Recognize MULT_HIGHPART_EXPR in tree-ssa-math-opts pass.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/104140] [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e
  2022-01-20  7:10 [Bug middle-end/104140] New: [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e belyshev at depni dot sinp.msu.ru
@ 2022-01-20  8:03 ` rguenth at gcc dot gnu.org
  2022-01-20 10:27 ` roger at nextmovesoftware dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-20  8:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104140

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
           Priority|P3                          |P1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/104140] [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e
  2022-01-20  7:10 [Bug middle-end/104140] New: [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e belyshev at depni dot sinp.msu.ru
  2022-01-20  8:03 ` [Bug middle-end/104140] " rguenth at gcc dot gnu.org
@ 2022-01-20 10:27 ` roger at nextmovesoftware dot com
  2022-01-20 10:47 ` roger at nextmovesoftware dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: roger at nextmovesoftware dot com @ 2022-01-20 10:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104140

Roger Sayle <roger at nextmovesoftware dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2022-01-20
           Assignee|unassigned at gcc dot gnu.org      |roger at nextmovesoftware dot com

--- Comment #1 from Roger Sayle <roger at nextmovesoftware dot com> ---
Mine (perhaps?).  To quote the review from my HIGHPART_MULT_EXPR patch:
>+  if (optype != TREE_TYPE (mop2)
>
> I think mop1 and mop2 have to be compatible types (the tree-cfg.c
> GIMPLE verification only tests for same precision it seems but tree.def
> says they are of type T1).  That said, I think optype != TREE_TYPE (mop2)
> is superfluous and too conservative at it.

It turns out that restoring this clause from the original patch submission
resolves this ICE on a cross-compiler to riscv-unknown-linux-gnu.

diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index 1b6a57b..89a26dd 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -4600,7 +4600,8 @@ convert_mult_to_highpart (gassign *stmt,
gimple_stmt_itera
   bool unsignedp = TYPE_UNSIGNED (optype);
   unsigned int prec = TYPE_PRECISION (optype);

-  if (unsignedp != TYPE_UNSIGNED (mtype)
+  if (optype != TREE_TYPE (mop2)
+      || unsignedp != TYPE_UNSIGNED (mtype)
       || TYPE_PRECISION (mtype) != 2 * prec)
     return false;

It's odd that I'm unable to reproduce a similar failure on x86_64.
Perhaps the above paranoid fix isn't the correct solution at all, as
before/with it, I'm seeing:

void g ()
{
  int x.0_2;
  unsigned int v.1_4;
  long long int _6;
  long long int _7;
  unsigned int _8;

  <bb 2> [local count: 1073741824]:
  x.0_2 = x;
  v.1_4 = v;
  _6 = x.0_2 w* v.1_4;
  _7 = _6 >> 32;
  _8 = (unsigned int) _7;
  u = _8;
  return;

}

Note the differing operand types to the widening multiplication.  Perhaps the
upstream widening multiplication perception is the true source of the problem,
and just not being caught by verify_gimple like MULT_HIGHPART_EXPR is.

More generally, "defensive programming", i.e. the use of seemingly superfluous
tests that confirm assumed invariants isn't always a bad thing (in software
as complex as GCC).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/104140] [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e
  2022-01-20  7:10 [Bug middle-end/104140] New: [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e belyshev at depni dot sinp.msu.ru
  2022-01-20  8:03 ` [Bug middle-end/104140] " rguenth at gcc dot gnu.org
  2022-01-20 10:27 ` roger at nextmovesoftware dot com
@ 2022-01-20 10:47 ` roger at nextmovesoftware dot com
  2022-01-20 11:00 ` roger at nextmovesoftware dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: roger at nextmovesoftware dot com @ 2022-01-20 10:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104140

--- Comment #2 from Roger Sayle <roger at nextmovesoftware dot com> ---
Ah.  risv.md provides a usmulsidi3 expander that populates a usmul_widen_optab,
performing a widening multiplication with operands of differing signs.
The comment/documentation in tree.def needs to be updated to reflect that
the operands of WIDEN_MULT_EXPR may be different signs, but the same precision.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/104140] [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e
  2022-01-20  7:10 [Bug middle-end/104140] New: [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e belyshev at depni dot sinp.msu.ru
                   ` (2 preceding siblings ...)
  2022-01-20 10:47 ` roger at nextmovesoftware dot com
@ 2022-01-20 11:00 ` roger at nextmovesoftware dot com
  2022-01-21 18:51 ` cvs-commit at gcc dot gnu.org
  2022-01-21 19:28 ` belyshev at depni dot sinp.msu.ru
  5 siblings, 0 replies; 7+ messages in thread
From: roger at nextmovesoftware dot com @ 2022-01-20 11:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104140

--- Comment #3 from Roger Sayle <roger at nextmovesoftware dot com> ---
Sorry for the noise, but interestingly riscv.md also defines a
usmulsi3_highpart instruction, providing highpart multiplication with different
operand signedness. So in theory an alternate fix might be to allow/support
this in MULT_HIGHPART_EXPR (like in WIDEN_MULT_EXPR).  Perhaps a simple fix for
GCC 12, and a more intrusive solution (providing improved riscv support) for
GCC 13, once we return to stage 1.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/104140] [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e
  2022-01-20  7:10 [Bug middle-end/104140] New: [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e belyshev at depni dot sinp.msu.ru
                   ` (3 preceding siblings ...)
  2022-01-20 11:00 ` roger at nextmovesoftware dot com
@ 2022-01-21 18:51 ` cvs-commit at gcc dot gnu.org
  2022-01-21 19:28 ` belyshev at depni dot sinp.msu.ru
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-21 18:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104140

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Roger Sayle <sayle@gcc.gnu.org>:

https://gcc.gnu.org/g:886e9779581102caf97cd05dea80d9be87c24784

commit r12-6804-g886e9779581102caf97cd05dea80d9be87c24784
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Fri Jan 21 18:42:30 2022 +0000

    PR middle-end/104140: bootstrap ICE on riscv.

    This patch resolves the P1 "ice-on-valid-code" regression boostrapping
    GCC on risv-unknown-linux-gnu caused by my recent MULT_HIGHPART_EXPR
    functionality.  RISC-V differs from x86_64 and many targets by
    supporting a usmusidi3 instruction, basically a widening multiply
    where one operand is signed and the other is unsigned.  Alas the
    final version of my patch to recognize MULT_HIGHPART_EXPR didn't
    sufficiently defend against the operands of WIDEN_MULT_EXPR having
    different signedness.  This is fixed by the two-line change to
    tree-ssa-math-opts.cc's convert_mult_to_highpart in the patch below.

    The majority of the rest of the patch is to the documentation
    (in tree.def and generic.texi).  It turns out that WIDEN_MULT_EXPR
    wasn't previously documented in generic.texi, let alone the slightly
    unusual semantics of allowing mismatched (signed vs unsigned) operands.
    This also clarifies that MULT_HIGHPART_EXPR currently requires the
    signedness of operands to match [but this might change in a future
    release of GCC to support targets with usmul<mode>3_highpart].

    The one final chunk of this patch (that is hopefully sufficiently
    close to obvious for stage 4) is a similar (NULL pointer) sanity
    check in riscv_cpu_cpp_builtins.  Currently running cc1 from the
    command line (or from gdb) without specifying -march results in a
    segmentation fault (ICE).  This is a minor annoyance tracking down
    issues (in cross compilers) for riscv, and trivially fixed as below.

    2022-01-22  Roger Sayle  <roger@nextmovesoftware.com>

    gcc/ChangeLog
            PR middle-end/104140
            * tree-ssa-math-opts.cc (convert_mult_to_highpart): Check that the
            operands of the widening multiplication are either both signed or
            both unsigned, and abort the conversion if mismatched.
            * doc/generic.texi (WIDEN_MULT_EXPR): Describe expression node.
            (MULT_HIGHPART_EXPR): Clarify that operands must have the same
            signedness.
            * tree.def (MULT_HIGHPART_EXPR): Document both operands must have
            integer types with the same precision and signedness.
            (WIDEN_MULT_EXPR): Document that operands must have integer types
            with the same precision, but possibly differing signedness.
            * config/riscv/riscv-c.cc (riscv_cpu_cpp_builtins): Defend against
            riscv_current_subset_list returning a NULL pointer (empty list).

    gcc/testsuite/ChangeLog
            PR middle-end/104140
            * gcc.target/riscv/pr104140.c: New test case.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/104140] [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e
  2022-01-20  7:10 [Bug middle-end/104140] New: [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e belyshev at depni dot sinp.msu.ru
                   ` (4 preceding siblings ...)
  2022-01-21 18:51 ` cvs-commit at gcc dot gnu.org
@ 2022-01-21 19:28 ` belyshev at depni dot sinp.msu.ru
  5 siblings, 0 replies; 7+ messages in thread
From: belyshev at depni dot sinp.msu.ru @ 2022-01-21 19:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104140

Serge Belyshev <belyshev at depni dot sinp.msu.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Serge Belyshev <belyshev at depni dot sinp.msu.ru> ---
Fixed.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-01-21 19:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-20  7:10 [Bug middle-end/104140] New: [12 Regression] ICE verify_gimple failed: type mismatch in binary expression since r12-6434-g0752c75536e belyshev at depni dot sinp.msu.ru
2022-01-20  8:03 ` [Bug middle-end/104140] " rguenth at gcc dot gnu.org
2022-01-20 10:27 ` roger at nextmovesoftware dot com
2022-01-20 10:47 ` roger at nextmovesoftware dot com
2022-01-20 11:00 ` roger at nextmovesoftware dot com
2022-01-21 18:51 ` cvs-commit at gcc dot gnu.org
2022-01-21 19:28 ` belyshev at depni dot sinp.msu.ru

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).