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

            Bug ID: 126096
           Summary: ICE while folding predicate-as-counter svwhilelt
                    variant
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: artemiyv at gcc dot gnu.org
  Target Milestone: ---

$ /work/t$ cat test.c
#include <arm_sve.h>
void f() { svcount_t b = svwhilelt_c64_u64(2, 8, 2); }
$ /work/t$ /work/install/gcc/bin/gcc -O3 -march=armv9-a+sve2p1 -S test.c
during GIMPLE pass: lower
test.c: In function ‘f’:
test.c:2:6: internal compiler error: Segmentation fault
    2 | void f() { svcount_t b = svwhilelt_c64_u64(2, 8, 2); }
      |      ^
0x3da512f internal_error(char const*, ...)
        /work/src/gcc/gcc/diagnostic-global-context.cc:787
0x1c31f03 crash_signal
        /work/src/gcc/gcc/toplev.cc:325
0x20e681c build_all_ones_cst(tree_node*)
        /work/src/gcc/gcc/tree.cc:2728
0x243c563 aarch64_acle::gimple_folder::fold_to_vl_pred(unsigned int)
        /work/src/gcc/gcc/config/aarch64/aarch64-acle-builtins.cc:2987
0x2462cb3 fold_type<poly_int<2, long unsigned int> >
        /work/src/gcc/gcc/config/aarch64/aarch64-sve-builtins-base.cc:3428
0x2462783 fold
        /work/src/gcc/gcc/config/aarch64/aarch64-sve-builtins-base.cc:3447
0x243ce47 aarch64_acle::gimple_folder::fold()
        /work/src/gcc/gcc/config/aarch64/aarch64-acle-builtins.cc:3094
0x244288b aarch64_acle::gimple_fold_builtin(unsigned int,
gimple_stmt_iterator*, gcall*)
        /work/src/gcc/gcc/config/aarch64/aarch64-acle-builtins.cc:4310
0x2221f5f aarch64_gimple_fold_builtin
        /work/src/gcc/gcc/config/aarch64/aarch64.cc:16933
0x165a14f gimple_fold_call
        /work/src/gcc/gcc/gimple-fold.cc:6174
0x165df9f fold_stmt_1
        /work/src/gcc/gcc/gimple-fold.cc:7016
0x165e207 fold_stmt(gimple_stmt_iterator*, bitmap_head*)
        /work/src/gcc/gcc/gimple-fold.cc:7096
0x38b6e9f lower_stmt
        /work/src/gcc/gcc/gimple-low.cc:874
0x38b4aa7 lower_sequence
        /work/src/gcc/gcc/gimple-low.cc:266
0x38b6a5b lower_stmt
        /work/src/gcc/gcc/gimple-low.cc:741
0x38b4aa7 lower_sequence
        /work/src/gcc/gcc/gimple-low.cc:266
0x38b7363 lower_gimple_bind
        /work/src/gcc/gcc/gimple-low.cc:963
0x38b4633 lower_function_body
        /work/src/gcc/gcc/gimple-low.cc:147
0x38b4a07 execute
        /work/src/gcc/gcc/gimple-low.cc:243
/work/install/gcc/libexec/gcc/aarch64-unknown-linux-gnu/17.0.0/cc1 -quiet
-imultiarch aarch64-linux-gnu test.c -mno-fix-cortex-a53-835769
-mno-fix-cortex-a53-843419 -quiet -dumpbase test.c -dumpbase-ext .c
-march=armv9-a+sve2p1 -mlittle-endian -mabi=lp64 -O3 -o test.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

I suspect this is because when adding this variant as part of SVE2.1, we never
updated svwhilelx_impl::fold_type (), which still calls fold_to_vl_pred () that
assumes that the return type is VNx16BI and crashes here:

  tree vectype = TREE_TYPE (lhs);
  tree element_type = TREE_TYPE (vectype);                                      
  tree minus_one = build_all_ones_cst (element_type); 

because `TREE_TYPE (lhs)` is in fact svcount_t (a RECORD_TYPE), and thus
`element_type` is NULL.

gcc -v output:

$ /work/install/gcc/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/work/install/gcc/bin/gcc
COLLECT_LTO_WRAPPER=/work/install/gcc/libexec/gcc/aarch64-unknown-linux-gnu/17.0.0/lto-wrapper
Target: aarch64-unknown-linux-gnu
Configured with: /work/src/gcc/configure --prefix=/work/install/gcc
--disable-bootstrap --enable-languages=c,c++,fortran --disable-thread
--disable-tls --disable-libsanitizer
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 17.0.0 20260702 (experimental) (GCC)

Reply via email to