[all-commits] [llvm/llvm-project] 84bd98: [SLP] no need to generate extract for in-tree uses...

Enna1 via All-commits all-commits at lists.llvm.org
Wed Dec 20 09:04:58 PST 2023


  Branch: refs/heads/users/Enna1/slp-extract-in-tree-user
  Home:   https://github.com/llvm/llvm-project
  Commit: 84bd9888bbac34f707c2321378fe572b985aaf9c
      https://github.com/llvm/llvm-project/commit/84bd9888bbac34f707c2321378fe572b985aaf9c
  Author: xumingjie.enna1 <xumingjie.enna1 at bytedance.com>
  Date:   2023-12-21 (Thu, 21 Dec 2023)

  Changed paths:
    M llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
    M llvm/test/Transforms/SLPVectorizer/X86/opaque-ptr.ll

  Log Message:
  -----------
  [SLP] no need to generate extract for in-tree uses for original scalar instruction.

Before https://github.com/llvm/llvm-project/commit/77a609b55636dc540090ef9105c60a99cfdbd1dd,
we always skip in-tree uses of the vectorized scalars in `buildExternalUses()`,
that commit handle the case that if the in-tree use is scalar operand in vectorized instruction,
we need to generate extract for these in-tree uses.

in-tree uses remain as scalar in vectorized instructions can be 3 cases:
- The pointer operand of vectorized LoadInst uses an in-tree scalar
- The pointer operand of vectorized StoreInst uses an in-tree scalar
- The scalar argument of vector form intrinsic uses an in-tree scalar

Generating extract for in-tree uses for vectorized instructions are implemented in BoUpSLP::vectorizeTree():
- pointer operand of vectorized LoadInst: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp#L11497-L11506
- https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp#L11542-L11551
- https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp#L11657-L11667

However, that commit no only generates extract for vectorized instructions,
but also generate extract for original scalar instructions.

There is no need to generate extract for origin scalar instrutions,
as these scalar instructions will be replaced by vector instructions and get erased later.
Extract for origin scalar instrutions are also generated because
in `BoUpSLP::buildExternalUses()` if `doesInTreeUserNeedToExtract()` return true,
<in-tree scalar, scalar instruction use in-tree scalar> will be pushed to `ExternalUses`.

To omit generating extract for original scalar instruction, this patch remove `doesInTreeUserNeedToExtract()` check, and fold the follwing if expression to always true.
```
if (UseScalar != U ||
    UseEntry->State == TreeEntry::ScatterVectorize ||
    UseEntry->State == TreeEntry::PossibleStridedVectorize ||
    !doesInTreeUserNeedToExtract(Scalar, UserInst, TLI))
```

With this change, it is also more likely to be profitable to vectorize since we remove the unneed entries in `ExternalUses` and get less extraction cost.
E.g. the llvm/test/Transforms/SLPVectorizer/X86/opaque-ptr.ll testcase is updated as the `test2()` function is successfully vectorized with this change.




More information about the All-commits mailing list