[llvm] [SandboxVec] Add a simple pack reuse pass (PR #141848)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 3 09:29:29 PDT 2025
================
@@ -179,13 +197,61 @@ class VecUtils {
/// \Returns the first integer power of 2 that is <= Num.
static unsigned getFloorPowerOf2(unsigned Num);
+ /// If \p I is the last instruction of a pack pattern, then this function
+ /// returns the instructions in the pack and the operands in the pack, else
+ /// returns nullopt.
+ static std::optional<
+ std::pair<SmallVector<Instruction *>, SmallVector<Value *>>>
+ matchPack(Instruction *I) {
+ // TODO: Support vector pack patterns.
+ // TODO: Support out-of-order inserts.
+
+ // Early return if `I` is not an Insert.
+ if (!isa<InsertElementInst>(I))
+ return std::nullopt;
+ auto *BB0 = I->getParent();
+ // The pack contains as many instrs as the lanes of the bottom-most Insert
+ unsigned ExpectedNumInserts = VecUtils::getNumLanes(I);
+ assert(ExpectedNumInserts >= 2 && "Expected at least 2 inserts!");
+ SmallVector<Instruction *> PackInstrs;
+ SmallVector<Value *> PackOperands;
+ PackOperands.resize(ExpectedNumInserts);
+ // Collect the inserts by walking up the use-def chain.
+ Instruction *InsertI = I;
+ for ([[maybe_unused]] auto Cnt : seq<unsigned>(ExpectedNumInserts)) {
----------------
vporpo wrote:
Ah yes, thanks for the suggestion, it looks a lot better now.
https://github.com/llvm/llvm-project/pull/141848
More information about the llvm-commits
mailing list