Link to the Compiler Explorer: https://godbolt.org/z/bWdof9c8s Reproducer: int a; long b; extern int c[], d[]; extern bool e[]; void f() { if (a) ; for (;;) { for (int g = 2; g; g = a) d[g] = 0; for (int h = 1; h < 13; h++) e[h] = b ? (short)c[4 + h - 1] : c[4 + h - 1]; } } Error: >$ g++ -O3 -march=skylake-avx512 -c func.cpp during GIMPLE pass: slp func.cpp: In function 'void f()': func.cpp:5:6: internal compiler error: in vectorizable_phi, at tree-vect-loop.c:7861 5 | void f() { | ^ 0x8bca05 vectorizable_phi(vec_info*, _stmt_vec_info*, gimple**, _slp_tree*, vec<stmt_info_for_cost, va_heap, vl_ptr>*) /testing/gcc/gcc_src_master/gcc/tree-vect-loop.c:7861 0x20abd84 vect_analyze_stmt(vec_info*, _stmt_vec_info*, bool*, _slp_tree*, _slp_instance*, vec<stmt_info_for_cost, va_heap, vl_ptr>*) /testing/gcc/gcc_src_master/gcc/tree-vect-stmts.c:11125 0x14a2186 vect_slp_analyze_node_operations_1 /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:4481 0x14a2186 vect_slp_analyze_node_operations /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:4640 0x14a2097 vect_slp_analyze_node_operations /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:4620 0x14a2097 vect_slp_analyze_node_operations /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:4620 0x14a2097 vect_slp_analyze_node_operations /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:4620 0x14a4811 vect_slp_analyze_operations(vec_info*) /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:4879 0x14a9605 vect_slp_analyze_bb_1 /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:5817 0x14a9605 vect_slp_region /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:5864 0x14aae33 vect_slp_bbs /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:6056 0x14ab22c vect_slp_function(function*) /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:6144 0x14b1c82 execute /testing/gcc/gcc_src_master/gcc/tree-vectorizer.c:1503 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. GCC version: gcc version 12.0.0 20211219 (fcbf94a5be9e0c1ecad92da773a6632b86b7f70a) (GCC)
You don't even need to have -march=skylake-avx512.
Started with r12-5626-g0194d92c35ca8b3a.
Mine.
So in this case we have an SLP tree for a merge PHI with scalar bools where we do t.c:10:12: note: using boolean precision 32 for iftmp.1_168 = pretmp_175 != 0; t.c:10:12: note: using boolean precision 16 for _177 = _176 != 0; t.c:10:12: note: using boolean precision 16 for iftmp.1_173 = PHI <iftmp.1_168(6), _177(7)> but pattern detection doesn't have any code to insert compensation on PHI edges. We now detect the mismatch but I fell foul of thinking it can only happen for non-bool vs. bool context ...
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:88e861655b3e59bc982ba22cd6e2e7348efae866 commit r12-6211-g88e861655b3e59bc982ba22cd6e2e7348efae866 Author: Richard Biener <rguenther@suse.de> Date: Tue Jan 4 15:49:50 2022 +0100 tree-optimization/103800 - sanity check more PHI vectorization Bool pattern detection doesn't really handle PHIs well so we have to be prepared for mismatched vector types in more cases than originally thought. 2022-01-04 Richard Biener <rguenther@suse.de> PR tree-optimization/103800 * tree-vect-loop.c (vectorizable_phi): Remove assert and expand comment. * gcc.dg/vect/bb-slp-pr103800.c: New testcase.
Fixed.