[LV] Allow tail folded reduction selects to remain in the loop
authorDavid Green <david.green@arm.com>
Thu, 20 Aug 2020 13:31:14 +0000 (14:31 +0100)
committerDavid Green <david.green@arm.com>
Thu, 20 Aug 2020 13:31:14 +0000 (14:31 +0100)
commit816097e4e5f32b59c2b6099f74356f1dbe55aabb
tree9ac2f6755e44dc27c5a1ee1591859e626ae85201
parentadf0b8cc70325f027d202139e3ff984c41896b57
[LV] Allow tail folded reduction selects to remain in the loop

The normal scheme for tail folding reductions is to use:

loop:
  p = phi(0, a)
  mask = ...
  x = masked_load(..., mask)
  a = add(x, p)
s = select(mask, a, p)

This means we need to keep the register p and a alive out of the loop, plus
the mask. On a target with predicated operations we can instead generate
the phi as p = phi(0, s). This ensures the select in the loop and we can
fold select(m, add(a, b), c) to something like a vaddt c, a, b using the
m predicate. This in turn allows us to tail predicate the entire loop.

Differential Revision: https://reviews.llvm.org/D84741
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/reduction-predselect.ll