diff options
author | Luke Lau <luke@igalia.com> | 2025-06-30 10:40:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-30 10:40:12 +0100 |
commit | d0c1ea928c5c4a99689ff3dcbf1ca578d56b80a3 (patch) | |
tree | 275979f5c79e0266e1867ac05c41ec8fe7bf9fec /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | |
parent | f226852265e6eca9c0f0633cc25dc5e1f30b2c55 (diff) | |
download | llvm-d0c1ea928c5c4a99689ff3dcbf1ca578d56b80a3.zip llvm-d0c1ea928c5c4a99689ff3dcbf1ca578d56b80a3.tar.gz llvm-d0c1ea928c5c4a99689ff3dcbf1ca578d56b80a3.tar.bz2 |
[InstCombine] Pull unary shuffles through fneg/fabs (#144933)
This canonicalizes fneg/fabs (shuffle X, poison, mask) -> shuffle
(fneg/fabs X), posion, mask
This undoes part of b331a7ebc1e02f9939d1a4a1509e7eb6cdda3d38 and
a8f13dbdeb31be37ee15b5febb7cc2137bbece67, but keeps the binary shuffle
case i.e. shuffle fneg, fneg, mask.
By pulling out the shuffle we bring it inline with the same
canonicalisation we perform on binary ops and intrinsics, which the
original commit acknowledges it goes in the opposite direction.
However nowadays VectorCombine is more powerful and can do more
optimisations when the shuffle is pulled out, so I think we should
revisit this. In particular we get more shuffles folded and can perform
scalarization.
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 418302d..e721f0c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -3044,6 +3044,11 @@ Instruction *InstCombinerImpl::visitFNeg(UnaryOperator &I) { return replaceInstUsesWith(I, NewCopySign); } + // fneg (shuffle x, Mask) --> shuffle (fneg x), Mask + ArrayRef<int> Mask; + if (match(OneUse, m_Shuffle(m_Value(X), m_Poison(), m_Mask(Mask)))) + return new ShuffleVectorInst(Builder.CreateFNegFMF(X, &I), Mask); + return nullptr; } |