Bug 108793 - [12 Regression] ICE: verify_gimple failed since r12-3136-g3673dcf6d6baeb67
Summary: [12 Regression] ICE: verify_gimple failed since r12-3136-g3673dcf6d6baeb67
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 13.0
: P2 normal
Target Milestone: 12.3
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2023-02-14 19:37 UTC by G. Steinmetz
Modified: 2023-03-15 10:04 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-pc-linux-gnu
Build:
Known to work: 12.2.1, 13.0
Known to fail: 12.2.0
Last reconfirmed: 2023-02-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2023-02-14 19:37:13 UTC
Started between 20210822 and 20210905, at -O3 or -Ofast :
(gcc configured with --enable-checking=yes)


$ cat z1.cc
typedef void (*p)();
extern "C" p a, b;
int f () {
  int n = 0;
  for (p* i = &a; i > &b; i++) {
    n++;
  }
  return n;
}


$ gcc-13-20230212 -c z1.cc -Ofast
z1.cc: In function 'int f()':
z1.cc:3:5: error: non-trivial conversion in unary operation
    3 | int f () {
      |     ^
unsigned long
void (*p) (void) *
_3 = ~_1;
z1.cc:3:5: error: non-trivial conversion in unary operation
unsigned long
void (*p) (void) *
_24 = ~_23;
during GIMPLE pass: vect
z1.cc:3:5: internal compiler error: verify_gimple failed
0x12942be verify_gimple_in_cfg(function*, bool, bool)
        ../../gcc/tree-cfg.cc:5648
0x1135053 execute_function_todo
        ../../gcc/passes.cc:2091
0x1135ad2 execute_todo
        ../../gcc/passes.cc:2145
Comment 1 Andrew Pinski 2023-02-14 19:43:04 UTC
Confirmed. Version without function pointers:
typedef int *p;
extern p a[], b[];
int f () {
  int n = 0;
  for (p* i = &a[0]; i > &b[0]; i++)
    n++;
  return n;
}
Comment 2 Richard Biener 2023-02-15 08:38:52 UTC
I will have a look.
Comment 3 Richard Biener 2023-02-20 11:57:59 UTC
It's caused by -1 -A -> ~A being invoked from number_of_iterations_until_wrap:

1497          num = fold_build2 (MINUS_EXPR, niter_type, wide_int_to_tree (type, max),
1498                             iv1->base);
(gdb) p iv1->base
$3 = <addr_expr 0x7ffff6a77560>
(gdb) p niter_type
$4 = <integer_type 0x7ffff68e81f8>

while _until_wrap probably doesn't make much sense for pointer IVs, the above
has signed vs. unsigned type issues anyway.
Comment 4 GCC Commits 2023-02-21 13:03:22 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:a7e706df2280de4a42f68b6c44401e4348d3593c

commit r13-6258-ga7e706df2280de4a42f68b6c44401e4348d3593c
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Feb 20 12:58:50 2023 +0100

    tree-optimization/108793 - niter compute type mismatch
    
    When computing the number of iterations until wrap types are mixed up,
    eventually leading to checking ICEs with a pointer bitwise inversion.
    The following uses niter_type for the calculation.
    
            PR tree-optimization/108793
            * tree-ssa-loop-niter.cc (number_of_iterations_until_wrap):
            Use convert operands to niter_type when computing num.
    
            * gcc.dg/torture/pr108793.c: New testcase.
Comment 5 Martin Liška 2023-02-23 14:56:25 UTC
Started with r12-3136-g3673dcf6d6baeb67.
Comment 6 GCC Commits 2023-03-15 09:48:09 UTC
The releases/gcc-12 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:0a3642dde799ee2be9f2b60ec361191176390005

commit r12-9259-g0a3642dde799ee2be9f2b60ec361191176390005
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Feb 20 12:58:50 2023 +0100

    tree-optimization/108793 - niter compute type mismatch
    
    When computing the number of iterations until wrap types are mixed up,
    eventually leading to checking ICEs with a pointer bitwise inversion.
    The following uses niter_type for the calculation.
    
            PR tree-optimization/108793
            * tree-ssa-loop-niter.cc (number_of_iterations_until_wrap):
            Use convert operands to niter_type when computing num.
    
            * gcc.dg/torture/pr108793.c: New testcase.
    
    (cherry picked from commit a7e706df2280de4a42f68b6c44401e4348d3593c)
Comment 7 Richard Biener 2023-03-15 10:04:07 UTC
Fixed.