Jakub Jelinek <ja...@redhat.com> writes: > On Tue, Aug 28, 2018 at 12:24:06PM +0100, Richard Sandiford wrote: >> The point of this patch is to put pattern statements in the same >> vec_basic_block as the statements they replace, with the pattern >> statements for S coming between S and S's original predecessor. >> This removes the need to handle them specially in various places. > > My preferred way to handle pattern stmts would be to do what we do in > tree-if-conversion, i.e. whenever creating first pattern stmt for certain > loop, duplicate that loop directly in the IL guarded with an ifn > and modify directly one copy of the loop (the one meant to be vectorized). > If we aren't cycling over multiple vectorization factors, that could be even > done directly on the tree-if-conversion created vector loop copy, otherwise > we'd need more.
I'd originally tried adding the pattern stmts to the gimple bb as well as the vec_basic_block, but the problem is that we create pattern stmts before duplicating the scalar loop for peeling. So I think we'd need to copy the loop even for the single-size case, or arrange some other way of temporarily restoring the original code. And like you say, there's the problem of trying multiple vector sizes. We'd need to either copy the IL for each size or make sure that we can reliably roll back to the original scalar code. Rolling back would make it harder to try all available vector sizes and pick the cheapest, since we'd have to reroll the pattern statements for the chosen size. Thanks, Richard