[llvm] [InstCombine] Added pattern for recognising the construction of packed integers. (PR #147414)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 24 09:57:12 PDT 2025
================
@@ -3592,6 +3595,154 @@ static Value *foldOrOfInversions(BinaryOperator &I,
return nullptr;
}
+/// Match \p V as "shufflevector -> bitcast" or "extractelement -> zext -> shl"
+/// patterns, which extract vector elements and pack them in the same relative
+/// positions.
+///
+/// \p Vec is the underlying vector being extracted from.
+/// \p Mask is a bitmask identifying which packed elements are obtained from the
+/// vector.
+/// \p VecOffset is the vector element corresponding to index 0 of the
+/// mask.
+static bool matchSubIntegerPackFromVector(Value *V, Value *&Vec,
+ int64_t &VecOffset,
+ SmallBitVector &Mask,
+ const DataLayout &DL) {
+ static const auto m_ConstShlOrSelf = [](const auto &Base, uint64_t &ShlAmt) {
+ ShlAmt = 0;
+ return m_CombineOr(m_Shl(Base, m_ConstantInt(ShlAmt)), Base);
----------------
dtcxzyw wrote:
We may need a helper like `m_ShlLike/m_LShrLike` to match a constant shift or the value itself. This pattern is also used in AggressiveInstCombine.
https://github.com/llvm/llvm-project/blob/3003e4e8616015cd247ccbede67598ac544825da/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp#L877-L880
https://github.com/llvm/llvm-project/blob/3003e4e8616015cd247ccbede67598ac544825da/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp#L647-L652
https://github.com/llvm/llvm-project/blob/3003e4e8616015cd247ccbede67598ac544825da/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp#L663-L665
cc @nikic
https://github.com/llvm/llvm-project/pull/147414
More information about the llvm-commits
mailing list