Link to the Compiler Explorer: https://godbolt.org/z/xedcfP338 Reproducer: short a; extern int b[]; int c; void d(long f[][5][5][17], int g[][5][5][17]) { for (short e = 0; e < 17; e++) { a = g[19][2][3][e]; b[e] = c & (f[3][2][3][e] && g[19][2][3][e]); } } Error: >$ g++ -march=skylake-avx512 -c -O3 func.cpp during GIMPLE pass: slp func.cpp: In function 'void d(long int (*)[5][5][17], int (*)[5][5][17])': func.cpp:4:6: internal compiler error: in operator[], at vec.h:889 4 | void d(long f[][5][5][17], int g[][5][5][17]) { | ^ 0x99508e vec<edge_def*, va_gc, vl_embed>::operator[](unsigned int) /testing/gcc/gcc_src_master/gcc/vec.h:889 0x996d5b vec<tree_node*, va_heap, vl_embed>::operator[](unsigned int) /testing/gcc/gcc_src_master/gcc/tree-vect-stmts.cc:6108 0x996d5b vec<tree_node*, va_heap, vl_ptr>::operator[](unsigned int) /testing/gcc/gcc_src_master/gcc/vec.h:1495 0x996d5b vectorizable_operation /testing/gcc/gcc_src_master/gcc/tree-vect-stmts.cc:6375 0x2123ab8 vect_transform_stmt(vec_info*, _stmt_vec_info*, gimple_stmt_iterator*, _slp_tree*, _slp_instance*) /testing/gcc/gcc_src_master/gcc/tree-vect-stmts.cc:11245 0x14c4fc7 vect_schedule_slp_node /testing/gcc/gcc_src_master/gcc/tree-vect-slp.cc:7320 0x14d6346 vect_schedule_scc /testing/gcc/gcc_src_master/gcc/tree-vect-slp.cc:7515 0x14d60d9 vect_schedule_scc /testing/gcc/gcc_src_master/gcc/tree-vect-slp.cc:7496 0x14d60d9 vect_schedule_scc /testing/gcc/gcc_src_master/gcc/tree-vect-slp.cc:7496 0x14d60d9 vect_schedule_scc /testing/gcc/gcc_src_master/gcc/tree-vect-slp.cc:7496 0x14d699f vect_schedule_slp(vec_info*, vec<_slp_instance*, va_heap, vl_ptr> const&) /testing/gcc/gcc_src_master/gcc/tree-vect-slp.cc:7632 0x14d8163 vect_slp_region /testing/gcc/gcc_src_master/gcc/tree-vect-slp.cc:5994 0x14d9113 vect_slp_bbs /testing/gcc/gcc_src_master/gcc/tree-vect-slp.cc:6106 0x14d950c vect_slp_function(function*) /testing/gcc/gcc_src_master/gcc/tree-vect-slp.cc:6194 0x14e13e2 execute /testing/gcc/gcc_src_master/gcc/tree-vectorizer.cc:1506 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. GCC version: gcc version 12.0.1 20220401 (git://gcc.gnu.org/git/gcc.git:master 15d683d4f0b390b27c54a7c92c6e4f33195bdc93) (GCC)
I will have a look.
So we end up scheduling t.ii:4:6: note: node 0x45e58d0 (max_nunits=16, refcnt=1) vector(8) <signed-boolean:1> t.ii:4:6: note: op template: patt_99 = _20 & patt_346; t.ii:4:6: note: stmt 0 patt_99 = _20 & patt_346; t.ii:4:6: note: stmt 1 patt_68 = _94 & patt_59; t.ii:4:6: note: stmt 2 patt_71 = _108 & patt_70; t.ii:4:6: note: stmt 3 patt_2 = _124 & patt_1; t.ii:4:6: note: stmt 4 patt_78 = _140 & patt_45; t.ii:4:6: note: stmt 5 patt_37 = _156 & patt_86; t.ii:4:6: note: stmt 6 patt_40 = _172 & patt_39; t.ii:4:6: note: stmt 7 patt_115 = _188 & patt_114; t.ii:4:6: note: stmt 8 patt_121 = _204 & patt_117; t.ii:4:6: note: stmt 9 patt_132 = _220 & patt_131; t.ii:4:6: note: stmt 10 patt_146 = _236 & patt_137; t.ii:4:6: note: stmt 11 patt_149 = _252 & patt_148; t.ii:4:6: note: stmt 12 patt_163 = _268 & patt_162; t.ii:4:6: note: stmt 13 patt_169 = _284 & patt_165; t.ii:4:6: note: stmt 14 patt_180 = _300 & patt_179; t.ii:4:6: note: stmt 15 patt_194 = _316 & patt_185; t.ii:4:6: note: children 0x45e5958 0x45e5af0 where the children are vectorized with mismatching vector types of vector(16) <signed-boolean:1> vs. vector(8) <signed-boolean:1> Oddly enough vectorizable_operation nowhere tests for compatible vector types of its operands ...
Started with r12-7246-g4963079769c99c40.
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:3eda57b4ae50b5fe57c174556f1daf3bd9a46b09 commit r12-7980-g3eda57b4ae50b5fe57c174556f1daf3bd9a46b09 Author: Richard Biener <rguenther@suse.de> Date: Mon Apr 4 10:31:15 2022 +0200 tree-optimization/105132 - add missing checking in vectorizable_operation The following adds missing verification that the input vectors have the same number of elements for vectorizable_operation. 2022-04-04 Richard Biener <rguenther@suse.de> PR tree-optimization/105132 * tree-vect-stmts.cc (vectorizable_operation): Check that the input vectors have the same number of elements. * gcc.dg/torture/pr105132.c: New testcase.
Fixed (maybe a missed optimization remains)