[llvm] [SandboxVec][LoadStoreVec] Add support for constants (PR #189769)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 6 10:27:31 PDT 2026
================
@@ -97,44 +97,74 @@ bool LoadStoreVec::runOnRegion(Region &Rgn, const Analyses &A) {
// TODO: For now we only support load operands.
// TODO: For now we don't cross BBs.
// TODO: For now don't vectorize if the loads have external uses.
- if (!all_of(Operands, [BB](Value *V) {
- auto *LI = dyn_cast<LoadInst>(V);
- if (LI == nullptr)
- return false;
- if (LI->getParent() != BB)
- return false;
- if (LI->hasNUsesOrMore(2))
- return false;
- return true;
- }))
- return false;
- // TODO: Try to avoid the extra copy to an instruction vector.
- SmallVector<Instruction *, 8> Loads;
- Loads.reserve(Operands.size());
- for (Value *Op : Operands)
- Loads.push_back(cast<Instruction>(Op));
-
- bool Consecutive = VecUtils::areConsecutive<LoadInst, Instruction>(
- Loads, A.getScalarEvolution(), *DL);
- if (!Consecutive)
- return false;
- if (!canVectorize(Loads, Sched))
+ bool AllLoads = all_of(Operands, [BB](Value *V) {
+ auto *LI = dyn_cast<LoadInst>(V);
+ if (LI == nullptr)
+ return false;
+ // TODO: For now we don't cross BBs.
+ if (LI->getParent() != BB)
+ return false;
+ if (LI->hasNUsesOrMore(2))
+ return false;
+ return true;
+ });
+ bool AllConstants =
+ all_of(Operands, [](Value *V) { return isa<Constant>(V); });
+ if (!AllLoads && !AllConstants)
return false;
- // Generate vector store and vector load
- Type *Ty = VecUtils::getCombinedVectorTypeFor(Bndl, *DL);
- Value *LdPtr = cast<LoadInst>(Loads[0])->getPointerOperand();
- // TODO: Compute alignment.
- Align LdAlign(1);
- auto LdWhereIt = std::next(VecUtils::getLowest(Loads)->getIterator());
- auto *VecLd =
- LoadInst::create(Ty, LdPtr, LdAlign, LdWhereIt, Ctx, "VecIinitL");
+ Value *VecOp = nullptr;
+ SmallVector<Instruction *, 8> Loads;
----------------
vporpo wrote:
It is declared outside the `if` because we are using it in `tryEraseDeadInstrs(Stores, Loads)` after we emit the stores. But I think we can pass `Operands` as the second argument of `tryEraseDeadInstrs(Stores, Operands)`.
https://github.com/llvm/llvm-project/pull/189769
More information about the llvm-commits
mailing list