[all-commits] [llvm/llvm-project] e762d4: [LoopVectorize] Teach LoopVectorizationLegality ab...

David Sherwood via All-commits all-commits at lists.llvm.org
Thu Sep 19 01:41:49 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e762d4dac762a3fc27c6e251086b6645d7543bb2
      https://github.com/llvm/llvm-project/commit/e762d4dac762a3fc27c6e251086b6645d7543bb2
  Author: David Sherwood <david.sherwood at arm.com>
  Date:   2024-09-19 (Thu, 19 Sep 2024)

  Changed paths:
    M llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
    M llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
    M llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
    M llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll
    M llvm/test/Transforms/LoopVectorize/control-flow.ll
    M llvm/test/Transforms/LoopVectorize/remarks-multi-exit-loops.ll
    A llvm/test/Transforms/LoopVectorize/simple_early_exit.ll

  Log Message:
  -----------
  [LoopVectorize] Teach LoopVectorizationLegality about more early exits (#107004)

This patch is split off from PR #88385 and concerns only the code
related to the legality of vectorising early exit loops. It is the first
step in adding support for vectorisation of a simple class of loops that
typically involves searching for something, i.e.

  for (int i = 0; i < n; i++) {
    if (p[i] == val)
      return i;
  }
  return n;

or

  for (int i = 0; i < n; i++) {
    if (p1[i] != p2[i])
      return i;
  }
  return n;

In this initial commit LoopVectorizationLegality will only consider
early exit loops legal for vectorising if they follow these criteria:

1. There are no stores in the loop.
2. The loop must have only one early exit like those shown in the above
example. I have referred to such exits as speculative early exits, to
distinguish from existing support for early exits where the
exit-not-taken count is known exactly at compile time.
3. The early exit block dominates the latch block.
4. The latch block must have an exact exit count.
5. There are no loads after the early exit block.
6. The loop must not contain reductions or recurrences. I don't see
anything fundamental blocking vectorisation of such loops, but I just
haven't done the work to support them yet.
7. We must be able to prove at compile-time that loops will not contain
faulting loads.

Tests have been added here:

  Transforms/LoopVectorize/AArch64/simple_early_exit.ll



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list