[llvm] [SLP]Remove emission of vector_insert/vector_extract instrinsics (PR #148007)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 11 00:51:07 PDT 2025


================
@@ -5815,26 +5815,30 @@ static InstructionCost getExtractWithExtendCost(
 static Value *createInsertVector(
     IRBuilderBase &Builder, Value *Vec, Value *V, unsigned Index,
     function_ref<Value *(Value *, Value *, ArrayRef<int>)> Generator = {}) {
+  if (isa<PoisonValue>(Vec) && isa<PoisonValue>(V))
+    return Vec;
   const unsigned SubVecVF = getNumElements(V->getType());
-  if (Index % SubVecVF == 0) {
-    Vec = Builder.CreateInsertVector(Vec->getType(), Vec, V, Index);
+  // Create shuffle, insertvector requires that index is multiple of
+  // the subvector length.
+  const unsigned VecVF = getNumElements(Vec->getType());
+  SmallVector<int> Mask(VecVF, PoisonMaskElem);
+  if (isa<PoisonValue>(Vec)) {
+    auto *Begin = std::next(Mask.begin(), Index);
+    std::iota(Begin, std::next(Begin, getNumElements(V->getType())), 0);
+    Vec = Builder.CreateShuffleVector(V, Mask);
+    return Vec;
+  }
+  std::iota(Mask.begin(), Mask.end(), 0);
+  std::iota(std::next(Mask.begin(), Index),
+            std::next(Mask.begin(), Index + SubVecVF), VecVF);
+  if (Generator) {
+    Vec = Generator(Vec, V, Mask);
----------------
RKSimon wrote:

(style) `return Generator(Vec, V, Mask);` - and drop trailing else

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


More information about the llvm-commits mailing list