[llvm] [VectorCombine] Combine extract/insert from vector (PR #115213)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 8 02:59:31 PST 2024


================
@@ -2678,6 +2679,49 @@ bool VectorCombine::shrinkType(llvm::Instruction &I) {
   return true;
 }
 
+/// insert (DstVec, (extract SrcVec, ExtIdx), InsIdx) -->
+/// shuffle (DstVec, SrcVec, Mask)
+bool VectorCombine::foldInsExtVectorToShuffle(Instruction &I) {
+  Value *DstVec, *SrcVec;
+  uint64_t ExtIdx, InsIdx;
+  if (!match(&I, m_InsertElt(m_Value(DstVec),
+                             m_OneUse(m_ExtractElt(m_Value(SrcVec),
+                                                   m_ConstantInt(ExtIdx))),
+                             m_ConstantInt(InsIdx))))
+    return false;
+
+  auto *VecTy = dyn_cast<FixedVectorType>(I.getType());
+  if (!VecTy || SrcVec->getType() != VecTy)
+    return false;
+
+  unsigned NumElts = VecTy->getNumElements();
+  if (ExtIdx >= NumElts)
----------------
RKSimon wrote:

`if (ExtIdx >= NumElts || InsIdx >= NumElts)`

https://github.com/llvm/llvm-project/pull/115213


More information about the llvm-commits mailing list