With -Ofast -march=haswell -std=legacy -fno-aggressive-loop-optimizations this is somewhere stuck in SLP build not making progress.
Created attachment 51035 [details] reduced testcase Reduced testcase - it must get still smaller but it only very slowly reduces now.
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:90f78d5d86598f8cadacfb20d8d98c122a466599 commit r12-1670-g90f78d5d86598f8cadacfb20d8d98c122a466599 Author: Richard Biener <rguenther@suse.de> Date: Mon Jun 21 09:30:41 2021 +0200 tree-optimization/101121 - avoid infinite SLP build The following plugs another hole where we cache a failed SLP build attempt with an all-success 'matches'. It also adds checking that we don't do that. 2021-06-21 Richard Biener <rguenther@suse.de> PR tree-optimization/101121 * tree-vect-slp.c (vect_build_slp_tree_2): To not fail fatally when we just lack a stmt with the desired op when doing permutation. (vect_build_slp_tree): When caching a failed SLP build attempt assert that at least one lane is marked as not matching. * gfortran.dg/pr101121.f: New testcase.
Should be fixed now.