https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126291
Bug ID: 126291
Summary: [17 Regression] ICE: tree check: expected none of
vector_type, have vector_type in
`gimple_simplify_CONVERT_EXPR` since
r17-2276-ge2c4fc6b1cff
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: konstantinos.eleftheriou at vrull dot eu
Target Milestone: ---
Created attachment 65068
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65068&action=edit
reduced_testcase.c
The attached testcase ICEs on aarch64 trunk since r17-2276-ge2c4fc6b1cff.
Output:
$ gcc -O2 -funsafe-math-optimizations -mcpu=ampere1a testcase.c
during GIMPLE pass: fre
testcase.c: In function 'f':
testcase.c:2:8: internal compiler error: tree check: expected none of
vector_type, have vector_type in gimple_simplify_CONVERT_EXPR, at
gimple-match-1.cc:9943
2 | double f (const double *p, double x, double y, long n)
| ^
0x24a0b13 internal_error(char const*, ...)
../../gcc/gcc/diagnostic-global-context.cc:787
0x80e4b3 tree_not_check_failed(tree_node const*, char const*, int, char const*,
...)
../../gcc/gcc/tree.cc:9253
0x245024b tree_not_check(tree_node*, char const*, int, char const*, tree_code)
../../gcc/gcc/tree.h:3819
0x245024b gimple_simplify_CONVERT_EXPR(gimple_match_op*, gimple**, tree_node*
(*)(tree_node*), code_helper, tree_node*, tree_node*)
./gimple-match-1.cc:9943
0x1ac0b47 gimple_resimplify1
../../gcc/gcc/gimple-match-exports.cc:952
0x1ac15ff gimple_simplify(gimple*, gimple_match_op*, gimple**, tree_node*
(*)(tree_node*), tree_node* (*)(tree_node*))
../../gcc/gcc/gimple-match-exports.cc:896
0xc5658b gimple_fold_stmt_to_constant_1(gimple*, tree_node* (*)(tree_node*),
tree_node* (*)(tree_node*))
../../gcc/gcc/gimple-fold.cc:9652
0x12f8c93 try_to_simplify
../../gcc/gcc/tree-ssa-sccvn.cc:6542
0x12f8c93 visit_stmt
../../gcc/gcc/tree-ssa-sccvn.cc:6585
0x12f9a33 process_bb
../../gcc/gcc/tree-ssa-sccvn.cc:8511
0x12fb40b do_rpo_vn_1
../../gcc/gcc/tree-ssa-sccvn.cc:9098
0x12fcf67 execute
../../gcc/gcc/tree-ssa-sccvn.cc:9260
$ gcc -v
Using built-in specs.
COLLECT_GCC=/home/keleftheriou/gcc-master/install/usr/local/bin/gcc
COLLECT_LTO_WRAPPER=/home/keleftheriou/gcc-master/install/usr/local/bin/../libexec/gcc/aarch64-unknown-linux-gnu/17.0.0/lto-wrapper
Target: aarch64-unknown-linux-gnu
Configured with: ../gcc/configure --enable-shared --enable-checking=yes,extra
--with-system-zlib --enable-__cxa_atexit --enable-linker-build-id
--enable-plugin --with-isl --enable-lto --disable-nls
--enable-languages=c,c++,fortran --disable-bootstrap --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 17.0.0 20260716 (experimental) (GCC)
-----------------------------------
SLP packs dx and dy into a vector(2), so the (double)abs((int)...)
turns into a NOP-convert / abs / NOP-convert chain:
vect_dy_24.11_57 = (vector(2) signed long) vect__11.9_58;
vect_dy_24.10_56 = (vector(2) int) vect_dy_24.11_57;
vect__13.12_55 = ABS_EXPR <vect_dy_24.10_56>;
vect_ay_26.14_54 = (vector(2) signed long) vect__13.12_55;
and the outer convert is folded by the rule added in r17-2276-ge2c4fc6b1cff:
/* (trunc)abs (extend x) --> abs (x) */
(simplify
(convert (abs (convert@1 @0)))
(if (optimize
&& !HONOR_SNANS (@1)
&& types_match (type, TREE_TYPE (@0))
&& TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@1)))
(abs @0)))
type and TREE_TYPE (@0) are both v2di here, so types_match () succeeds and we
go on to call TYPE_PRECISION() on a vector type, which is what trips the tree
check. The fold can't apply anyway (the precision test 64 < 32 is false); the
guard simply isn't vector-safe.
Suggested fix:
Using element_precision(), which is vector-safe, in place of TYPE_PRECISION()
avoids the ICE. For vector types we also check that the target supports a
vector
abs, so the rule doesn't fold to an operation the target lacks (the existing
ABSU rule guards its vector case the same way):
&& element_precision (type) < element_precision (TREE_TYPE (@1))
&& (!VECTOR_TYPE_P (type)
|| target_supports_op_p (type, ABS_EXPR, optab_default))