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

            Bug ID: 121695
           Summary: [16 Regression] RISC-V: ICE in ifcvt tree check:
                    expected class 'type', have 'exceptional'
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ewlu at rivosinc dot com
  Target Milestone: ---

Created attachment 62218
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62218&action=edit
freport-bug output

Testcase:
int ac;
char p;
int *r;
static unsigned t = 7;
int q() {
  int v;
af: {
  int ag[3];
  int *ah = &ag[1];
  for (; ac;) {
    int ai = 3971866093;
    if (0 >= *ah && (*r = 1))
      *ah &= ai;
    else {
      if (p)
        goto af;
      *ah &= t;
    }
  }
}
  return v;
}

Commands/backtrace:
 /scratch/ewlu/daily-upstream-build/build-gcv/bin/riscv64-unknown-linux-gnu-gcc
-I/scratch/ewlu/ci/compiler-fuzz-ci/csmith-build/include -fsigned-char
-fno-strict-aliasing -fwrapv -march=rv64gcv -O3 red.c -o rv64gcv.out -w
-freport-bug
during GIMPLE pass: ifcvt
red.c: In function 'q':
red.c:5:5: internal compiler error: tree check: expected class 'type', have
'exceptional' (error_mark) in tree_single_nonnegative_warnv_p, at
fold-const.cc:14925
    5 | int q() {
      |     ^
0x2f02896 internal_error(char const*, ...)
        ../../../gcc/gcc/diagnostic-global-context.cc:534
0xc529f0 tree_class_check_failed(tree_node const*, tree_code_class, char
const*, int, char const*)
        ../../../gcc/gcc/tree.cc:9234
0xb59ff4 tree_class_check(tree_node*, tree_code_class, char const*, int, char
const*)
        ../../../gcc/gcc/tree.h:3888
0xb59ff4 tree_single_nonnegative_warnv_p(tree_node*, bool*, int)
        ../../../gcc/gcc/fold-const.cc:14925
0x1138609 gimple_phi_nonnegative_warnv_p
        ../../../gcc/gcc/gimple-fold.cc:11207
0x1138609 gimple_stmt_nonnegative_warnv_p(gimple*, bool*, int)
        ../../../gcc/gcc/gimple-fold.cc:11240
0x1138609 gimple_phi_nonnegative_warnv_p
        ../../../gcc/gcc/gimple-fold.cc:11207
0x1138609 gimple_stmt_nonnegative_warnv_p(gimple*, bool*, int)
        ../../../gcc/gcc/gimple-fold.cc:11240
0x10a20e6 tree_expr_nonnegative_warnv_p(tree_node*, bool*, int)
        ../../../gcc/gcc/tree.h:4758
0x10a20e6 tree_expr_nonnegative_p(tree_node*)
        ../../../gcc/gcc/fold-const.cc:15294
0x1d74f61 gimple_simplify_COND_EXPR(gimple_match_op*, gimple**, tree_node*
(*)(tree_node*), code_helper, tree_node*, tree_node*, tree_node*, tree_node*)
       
/scratch/ewlu/daily-upstream-build/build-gcv/build-gcc-linux-stage2/gcc/gimple-match-10.cc:53174
0x1e0c3fd gimple_resimplify3
        ../../../gcc/gcc/gimple-match-exports.cc:1096
0x15893e6 fold_build_cond_expr
        ../../../gcc/gcc/tree-if-conv.cc:515
0x15904c9 fold_build_cond_expr
        ../../../gcc/gcc/tree-if-conv.cc:498
0x15904c9 predicate_scalar_phi
        ../../../gcc/gcc/tree-if-conv.cc:2502
0x1590b69 predicate_all_scalar_phis
        ../../../gcc/gcc/tree-if-conv.cc:2652
0x1590b69 combine_blocks
        ../../../gcc/gcc/tree-if-conv.cc:3225
0x1594e21 tree_if_conversion(loop*, vec<gimple*, va_heap, vl_ptr>*)
        ../../../gcc/gcc/tree-if-conv.cc:4198
0x1595634 execute
        ../../../gcc/gcc/tree-if-conv.cc:4307
0x1595634 execute
        ../../../gcc/gcc/tree-if-conv.cc:4295
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Preprocessed source stored into /tmp/cczT0tvl.out file, please attach this to
your bugreport.

godbolt: https://godbolt.org/z/c4W4oc3Go

Bug doesn't appear with -O2 as seen in the godbolt.
Removing static from `static unsigned t = 7;` also causes bug to not trigger.
Changing `int ai = 3971866093;` to the int value (323101203) also causes the
bug to not trigger.


Found via fuzzer

Reply via email to