[llvm] [VectorCombine] Combine BinOp with extract/insert to vector BinOp (PR #115213)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 7 07:53:50 PST 2024
================
@@ -2678,6 +2679,52 @@ bool VectorCombine::shrinkType(llvm::Instruction &I) {
return true;
}
+/// insert (DstVec, (extract (binop), ExtIdx), InsIdx) -->
+/// shuffl (DstVec, (binop), Mask)
+bool VectorCombine::foldInsExtOfBinOpShuffle(Instruction &I) {
+ Value *DstVec;
+ BinaryOperator *BO;
+ uint64_t ExtIdx, InsIdx;
+ if (!match(&I, m_InsertElt(
+ m_Value(DstVec),
+ m_OneUse(m_ExtractElt(m_BinOp(BO), m_ConstantInt(ExtIdx))),
+ m_ConstantInt(InsIdx))))
+ return false;
+
+ if (!isSafeToSpeculativelyExecute(BO))
+ return false;
+
+ auto *VecTy = cast<FixedVectorType>(I.getType());
+ if (BO->getType() != VecTy)
+ return false;
+
+ unsigned NumElts = VecTy->getNumElements();
+ if (ExtIdx >= NumElts)
+ return false;
+
+ SmallVector<int> Mask(NumElts);
+ std::iota(Mask.begin(), Mask.end(), 0);
----------------
RKSimon wrote:
A splat is when the same value is assigned to every element - but for this shuffle mask you need `<0, 1, 2, 3, ..., N-1>` which is what iota will give you.
https://github.com/llvm/llvm-project/pull/115213
More information about the llvm-commits
mailing list