[LoopVectorize] Improve vectorisation of some intrinsics by treating them as uniform
authorDavid Sherwood <david.sherwood@arm.com>
Fri, 30 Jul 2021 07:41:31 +0000 (08:41 +0100)
committerDavid Sherwood <david.sherwood@arm.com>
Fri, 6 Aug 2021 09:13:15 +0000 (10:13 +0100)
commit3fd96e1b2e129b981f1bc1be2615486187e74687
treef022d12e3d480700971235568cc90eb650ac7f75
parent59f59d1c621cf6844c41fd92ad32a897fc9d10bd
[LoopVectorize] Improve vectorisation of some intrinsics by treating them as uniform

This patch adds more instructions to the Uniforms list, for example certain
intrinsics that are uniform by definition or whose operands are loop invariant.
This list includes:

  1. The intrinsics 'experimental.noalias.scope.decl' and 'sideeffect', which
  are always uniform by definition.
  2. If intrinsics 'lifetime.start', 'lifetime.end' and 'assume' have
  loop invariant input operands then these are also uniform too.

Also, in VPRecipeBuilder::handleReplication we check if an instruction is
uniform based purely on whether or not the instruction lives in the Uniforms
list. However, there are certain cases where calls to some intrinsics can
be effectively treated as uniform too. Therefore, we now also treat the
following cases as uniform for scalable vectors:

  1. If the 'assume' intrinsic's operand is not loop invariant, then we
  are free to treat this as uniform anyway since it's only a performance
  hint. We will get the benefit for the first lane.
  2. When the input pointers for 'lifetime.start' and 'lifetime.end' are loop
  variant then for scalable vectors we assume these still ultimately come
  from the broadcast of an alloca. We do not support scalable vectorisation
  of loops containing alloca instructions, hence the alloca itself would
  be invariant. If the pointer does not come from an alloca then the
  intrinsic itself has no effect.

I have updated the assume test for fixed width, since we now treat it
as uniform:

  Transforms/LoopVectorize/assume.ll

I've also added new scalable vectorisation tests for other intriniscs:

  Transforms/LoopVectorize/scalable-assume.ll
  Transforms/LoopVectorize/scalable-lifetime.ll
  Transforms/LoopVectorize/scalable-noalias-scope-decl.ll

Differential Revision: https://reviews.llvm.org/D107284
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/assume.ll
llvm/test/Transforms/LoopVectorize/scalable-assume.ll [new file with mode: 0644]
llvm/test/Transforms/LoopVectorize/scalable-lifetime.ll [new file with mode: 0644]
llvm/test/Transforms/LoopVectorize/scalable-noalias-scope-decl.ll [new file with mode: 0644]