[ARM] MVE Tail Predication
authorSam Parker <sam.parker@arm.com>
Fri, 6 Sep 2019 08:24:41 +0000 (08:24 +0000)
committerSam Parker <sam.parker@arm.com>
Fri, 6 Sep 2019 08:24:41 +0000 (08:24 +0000)
commit312409e464cd0e959e8ef8061144b2e8a4f02ab2
treed29f812ea55cefa8cb90417a8a82180bcb0f8ac5
parentf879c6875563c0a8cd838f1e13b14dd33558f1f8
[ARM] MVE Tail Predication

The MVE and LOB extensions of Armv8.1m can be combined to enable
'tail predication' which removes the need for a scalar remainder
loop after vectorization. Lane predication is performed implicitly
via a system register. The effects of predication is described in
Section B5.6.3 of the Armv8.1-m Arch Reference Manual, the key points
being:
- For vector operations that perform reduction across the vector and
  produce a scalar result, whether the value is accumulated or not.
- For non-load instructions, the predicate flags determine if the
  destination register byte is updated with the new value or if the
  previous value is preserved.
- For vector store instructions, whether the store occurs or not.
- For vector load instructions, whether the value that is loaded or
  whether zeros are written to that element of the destination
  register.

This patch implements a pass that takes a hardware loop, containing
masked vector instructions, and converts it something that resembles
an MVE tail predicated loop. Currently, if we had code generation,
we'd generate a loop in which the VCTP would generate the predicate
and VPST would then setup the value of VPR.PO. The loads and stores
would be placed in VPT blocks so this is not tail predication, but
normal VPT predication with the predicate based upon a element
counting induction variable. Further work needs to be done to finally
produce a true tail predicated loop.

Because only the loads and stores are predicated, in both the LLVM IR
and MIR level, we will restrict support to only lane-wise operations
(no horizontal reductions). We will perform a final check on MIR
during loop finalisation too.

Another restriction, specific to MVE, is that all the vector
instructions need operate on the same number of elements. This is
because predication is performed at the byte level and this is set
on entry to the loop, or by the VCTP instead.

Differential Revision: https://reviews.llvm.org/D65884

llvm-svn: 371179
12 files changed:
llvm/include/llvm/IR/IntrinsicsARM.td
llvm/lib/Target/ARM/ARM.h
llvm/lib/Target/ARM/ARMTargetMachine.cpp
llvm/lib/Target/ARM/CMakeLists.txt
llvm/lib/Target/ARM/MVETailPredication.cpp [new file with mode: 0644]
llvm/test/CodeGen/Thumb2/LowOverheadLoops/basic-tail-pred.ll [new file with mode: 0644]
llvm/test/CodeGen/Thumb2/LowOverheadLoops/nested.ll [new file with mode: 0644]
llvm/test/CodeGen/Thumb2/LowOverheadLoops/tail-pred-narrow.ll [new file with mode: 0644]
llvm/test/CodeGen/Thumb2/LowOverheadLoops/tail-pred-pattern-fail.ll [new file with mode: 0644]
llvm/test/CodeGen/Thumb2/LowOverheadLoops/tail-pred-widen.ll [new file with mode: 0644]
llvm/test/CodeGen/Thumb2/LowOverheadLoops/tail-reduce.ll [new file with mode: 0644]
llvm/test/CodeGen/Thumb2/LowOverheadLoops/vector-unroll.ll [new file with mode: 0644]