https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83922
--- Comment #3 from rsandifo at gcc dot gnu.org <rsandifo at gcc dot gnu.org> --- Author: rsandifo Date: Fri Jan 19 11:57:47 2018 New Revision: 256885 URL: https://gcc.gnu.org/viewcvs?rev=256885&root=gcc&view=rev Log: Check whether any statements need masking (PR 83922) This PR is an odd case in which, due to the low optimisation level, we enter vectorisation with: outer1: x_1 = PHI <x_3(outer2), ...>; ... inner: x_2 = 0; ... outer2: x_3 = PHI <x_2(inner)>; These statements are tentatively treated as a double reduction by vect_force_simple_reduction, but in the end only x_3 and x_2 are marked as relevant. vect_analyze_loop_operations skips over x_3, leaving the vectorizable_reduction check to a presumed future test of x_1, which in this case never happens. We therefore end up vectorising x_2 only (complete with peeling for niters!) and leave the scalar x_3 in place. This caused a segfault in the support for fully-masked loops, since there were no statements that needed masking. Fixed by checking for that. But I think this is also a flaw in vect_analyze_loop_operations. Outer loop vectorisation reduces the number of times that the inner loop is executed, so it wouldn't necessarily be valid to leave the scalar x_3 in place for all vectorisable x_2. There's already code to forbid that when x_1 isn't present: /* FORNOW: we currently don't support the case that these phis are not used in the outerloop (unless it is double reduction, i.e., this phi is vect_reduction_def), cause this case requires to actually do something here. */ I think we need to do the same if x_1 is present but not relevant. 2018-01-19 Richard Sandiford <richard.sandif...@linaro.org> gcc/ PR tree-optimization/83922 * tree-vect-loop.c (vect_verify_full_masking): Return false if there are no statements that need masking. (vect_active_double_reduction_p): New function. (vect_analyze_loop_operations): Use it when handling phis that are not in the loop header. gcc/testsuite/ PR tree-optimization/83922 * gcc.dg/pr83922.c: New test. Added: trunk/gcc/testsuite/gcc.dg/pr83922.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-vect-loop.c