https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110460
Bug ID: 110460 Summary: [14 Regression] ft32 ICE on 931110-1.c with new TYPE_PRECISION checking Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: law at gcc dot gnu.org Target Milestone: --- commit fe48f2651334bc4d96b6df6b2bb6b29fcb732a83 Author: Richard Biener <rguent...@suse.de> Date: Fri Jun 9 09:31:14 2023 +0200 Prevent TYPE_PRECISION on VECTOR_TYPEs The following makes sure that using TYPE_PRECISION on VECTOR_TYPE ICEs when tree checking is enabled. This should avoid wrong-code in cases like PR110182 and instead ICE. It also introduces a TYPE_PRECISION_RAW accessor and adjusts places I found that are eligible to use that. * tree.h (TYPE_PRECISION): Check for non-VECTOR_TYPE. (TYPE_PRECISION_RAW): Provide raw access to the precision field. * tree.cc (verify_type_variant): Compare TYPE_PRECISION_RAW. (gimple_canonical_types_compatible_p): Likewise. * tree-streamer-out.cc (pack_ts_type_common_value_fields): Stream TYPE_PRECISION_RAW. * tree-streamer-in.cc (unpack_ts_type_common_value_fields): Likewise. * lto-streamer-out.cc (hash_tree): Hash TYPE_PRECISION_RAW. gcc/lto/ * lto-common.cc (compare_tree_sccs_1): Use TYPE_PRECISION_RAW. One example on ft32-elf: Tests that now fail, but worked before (13 tests): ft32-sim: gcc.c-torture/execute/931110-1.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions (test for excess errors) ft32-sim: gcc.c-torture/execute/931110-1.c -O3 -g (test for excess errors) ft32-sim: gcc.dg/pr108095.c (test for excess errors) And if you dig into the 931110-1.c failure you find: ft32-sim: gcc.c-torture/execute/931110-1.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions (internal compiler error: tree check: expected none of vector_type, have vector_type in type_has_mode_precision_p, at tree.h:6644) ft32-sim: gcc.c-torture/execute/931110-1.c -O3 -g (internal compiler error: tree check: expected none of vector_type, have vector_type in type_has_mode_precision_p, at tree.h:6644) It looks like SCALAR_DEST in vectorizable_operation is actually a vector type -- meaning that STMT was already vectorized. This is the patch I'm testing. There are other failures that don't seem to be fixed by this patch. Anyway, the whole point of the change is to find these lurking bugs. diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index d642d3c257f..3dd8a284577 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -6481,6 +6481,10 @@ vectorizable_operation (vec_info *vinfo, scalar_dest = gimple_assign_lhs (stmt); vectype_out = STMT_VINFO_VECTYPE (stmt_info); + /* STMT may have already been vectorized. */ + if (VECTOR_TYPE_P (TREE_TYPE (scalar_dest))) + return false; + /* Most operations cannot handle bit-precision types without extra truncations. */ bool mask_op_p = VECTOR_BOOLEAN_TYPE_P (vectype_out);