[llvm] [SandboxVec][LoadStoreVec] Vectorize load seed chains (PR #215944)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 14:57:04 PDT 2026


================
@@ -200,19 +191,84 @@ bool LoadStoreVec::vectorizeStores(ArrayRef<Instruction *> Bndl, Region &Rgn,
   auto StWhereIt = std::next(VecUtils::getLowest(Bndl)->getIterator());
   StoreInst::create(VecOp, StPtr, StAlign, StWhereIt, Ctx);
 
-  tryEraseDeadInstrs(Bndl, Operands);
+  DenseSet<Instruction *> DeadInstrCandidates;
+  VecUtils::collectPotentiallyDeadInstrs(Bndl, DeadInstrCandidates);
+  if (AllLoads)
+    VecUtils::collectPotentiallyDeadInstrs(ArrayRef<Value *>(Operands),
+                                           DeadInstrCandidates);
+  VecUtils::tryEraseDeadInstrs(DeadInstrCandidates);
 
   return acceptOrRevert();
 }
 
+Value *LoadStoreVec::vectorizeLoads(ArrayRef<Instruction *> Bndl, Region &Rgn,
+                                    Scheduler &Sched, const Analyses &A,
+                                    bool OwnTransaction) {
+  Function &F = *Bndl[0]->getParent()->getParent();
+  auto &Ctx = F.getContext();
+  if (OwnTransaction)
+    saveIR(Rgn);
+
+  SmallVector<Value *, 8> Operands(Bndl.begin(), Bndl.end());
+  Value *VecLoad = createVectorLoad(Operands, Sched, A, Ctx);
+  if (VecLoad == nullptr) {
+    if (OwnTransaction)
+      Ctx.accept();
+    return nullptr;
+  }
+
+  if (!OwnTransaction)
+    return VecLoad;
+
+  // TODO: Support mixed-type top-level load chains.
+  Type *VecElemTy = cast<FixedVectorType>(VecLoad->getType())->getElementType();
+  if (!all_of(Bndl, [VecElemTy](Instruction *I) {
+        return VecUtils::getElementType(I->getType()) == VecElemTy;
+      })) {
+    Ctx.revert();
+    return nullptr;
+  }
+
+  auto *VecLoadI = cast<Instruction>(VecLoad);
----------------
vporpo wrote:

Shouldn't `createVectorLoad()` return an `Instruction *`, or even a `LoadInst *` ? Is there any case when it would not return an instruction ?

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


More information about the llvm-commits mailing list