[Polly] Isolate complete tiles from partial tiles in the tiling path (#221087)

Tiling an iteration space whose extent is not a multiple of the tile
size gives every point loop a min() upper bound. The loop vectorizer
cannot pick a fixed vector factor for such a loop without a runtime
check, and it has to emit a scalar epilogue inside the tile loop, so the
loops that carry the whole runtime of a tiled kernel are the ones it
handles worst.

Isolating the complete tiles from the partial ones gives the point loops
of the complete tiles constant bounds. Polly already does this for the
loop it strip-mines in the prevectorization path, added in commit
ca7f5bb ("Full/partial tile separation for vectorization"); this applies
the same technique to the loops produced by the regular tiling.
getPartialTilePrefixes is generalized to all point dimensions at once as
getCompleteTilePrefixes, and the resulting isolate option, combined with
atomic for the remaining part, is attached to the tile band.

The new -polly-isolate-complete-tiles option is off by default: it is a
large win where variable trip counts were what blocked vectorization,
but it also grows the generated code, so the default behaviour is left
unchanged.

On PolyBench/C 4.2.1 with -O3 -march=native -polly
-polly-vectorizer=none on a Ryzen 7 9700X, minimum of 5 to 41 runs
pinned to one core, it changes the code of 23 of the 30 kernels and
improves their geometric mean by 37.6%: 2mm 6.9x, 3mm 6.4x, gemm 6.4x,
covariance 4.2x, syrk 2.6x, jacobi-1d 2.1x, mvt/bicg/atax about 1.5x,
gemver 1.39x, jacobi-2d 1.35x, symm 1.23x, lu 1.17x. Two kernels
regress: gesummv by 19% and deriche by 6 to 12%. Both are already at a
limit the transformation cannot move -- gesummv streams 27 MB at 24 GB/s
against a measured single-core peak of 29.8 GB/s, and deriche is
dominated by loops that carry a dependence and never vectorize -- so for
them the extra code is pure cost.

These numbers are for problem sizes known at compile time, which is what
PolyBench gives Polly once the kernel is inlined into main. With the
sizes passed as parameters instead (-Dstatic= -fno-inline-functions),
the option improves the geometric mean of the 11 kernels whose run time
the tiling changes by 30.5%, and doitgen, which it does not change with
constant sizes, by 5.4x; gesummv regresses by 18%.

The cost is code size and compile time: the .text of the benchmark
binaries is 3.5x larger in geometric mean over the 23 kernels, from
1.11x for doitgen to 5.6x for mvt, and compiling a kernel file takes
1.64x as long, from 1.05x to 2.4x.

Two further options isolate the inner tiling levels in the same way:
-polly-isolate-complete-tiles-2nd-level for -polly-2nd-level-tiling, and
-polly-isolate-complete-register-tiles for -polly-register-tiling, where
it removes the guards from the unrolled point loops, as the matrix
multiplication optimization already does for its micro-kernel (commit
9989088ee99a). A complete first-level tile does not make the inner tiles
complete: they are complete only when the inner tile size divides the
outer one, and not along the diagonal of a triangular or skewed domain.
Both are off by default as well, because whether they pay off depends on
the problem sizes. Relative to the same flags without them, the
geometric mean of the run time is 0.965 for the second level and 0.997
for the register tiles when the sizes are known at compile time, and
1.056 and 0.934 when they are parametric. In the parametric case they
also roughly double the compile time, and they make AST generation
exceed -polly-astgen-computeout on up to 13 kernels, after which Polly
keeps the original code.

Numerical output is unchanged: every kernel produces byte-identical
dumps with and without the options, in all the configurations measured
and with constant as well as parametric sizes, on the MINI and MEDIUM
datasets, as do the eight largest winners on LARGE.

Assisted-by: Claude Opus 5

---------

Co-authored-by: Michael Kruse <llvm-project@meinersbur.de>
GitOrigin-RevId: 92c253c42b2744a530a3d1d3bfb4f5a798f9cdef
6 files changed