You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[SLP] no need to generate extract for in-tree uses for original scalar instruction.
Before 77a609b,
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():
- 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, 77a609b
not 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.
0 commit comments