[llvm] [SandboxVectorizer] Implement topdown vectorizer (PR #205249)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 22 20:54:57 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-vectorizers
@llvm/pr-subscribers-llvm-transforms
Author: Anshil Gandhi (gandhi56)
<details>
<summary>Changes</summary>
This patch introduces the `top-down-vec` pass to the Sandbox Vectorizer, adding the ability to traverse use-def chains top-down to discover and collect vectorization opportunities.
Key changes include:
* TopDownVec Pass: Implemented `TopDownVec` which recursively processes value bundles top-down, creates vectorization actions (widening, packing, shuffles), and emits the final vector IR.
* Shared Infrastructure (VecPassBase): Extracted common IR emission logic out of `BottomUpVec` and into a new shared base class, `VecPassBase`. Functions for generating vector instructions, handling diamond reuse, creating shuffles/packs, and collecting dead instructions are now shared between the bottom-up and top-down vectorizers to prevent code duplication.
* Pass Registration: Exposed `top-down-vec` in `PassRegistry.def` and `SandboxVectorizerPassBuilder`, allowing it to be invoked within pass pipelines via `opt`.
* Testing: Added comprehensive lit tests (such as `topdown_vec.ll`, `pack.ll`, and `external_uses.ll`) to verify correct top-down traversal, external use unpacking, and proper fallback to scalar packing.
---
Patch is 66.29 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/205249.diff
13 Files Affected:
- (modified) llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h (+3-55)
- (added) llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TopDownVec.h (+37)
- (added) llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/VecPassBase.h (+121)
- (modified) llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h (+7-1)
- (modified) llvm/lib/Transforms/Vectorize/CMakeLists.txt (+2)
- (modified) llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp (+2-281)
- (modified) llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def (+1)
- (added) llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/TopDownVec.cpp (+262)
- (added) llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/VecPassBase.cpp (+257)
- (modified) llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.cpp (+1)
- (modified) llvm/test/Transforms/SandboxVectorizer/external_uses.ll (+68)
- (modified) llvm/test/Transforms/SandboxVectorizer/pack.ll (+68-9)
- (added) llvm/test/Transforms/SandboxVectorizer/topdown_vec.ll (+94)
``````````diff
diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h
index d024bb74ac0c9..83db0ec237195 100644
--- a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h
@@ -15,10 +15,8 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/SandboxIR/Constant.h"
-#include "llvm/SandboxIR/Pass.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Transforms/Vectorize/SandboxVectorizer/InstrMaps.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Legality.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/VecPassBase.h"
namespace llvm::sandboxir {
@@ -32,65 +30,15 @@ namespace llvm::sandboxir {
/// profitable or not. For now profitability is checked at the end of the region
/// pass pipeline by a dedicated pass that accepts or rejects the IR
/// transaction, depending on the cost.
-class LLVM_ABI BottomUpVec final : public RegionPass {
- bool Change = false;
- /// The original instructions that are potentially dead after vectorization.
- DenseSet<Instruction *> DeadInstrCandidates;
- /// Maps scalars to vectors.
- std::unique_ptr<InstrMaps> IMaps;
+class LLVM_ABI BottomUpVec final : public VecPassBase {
/// Counter used for force-stopping the vectorizer after this many
/// invocations. Used for debugging miscompiles.
unsigned long BottomUpInvocationCnt = 0;
- /// Creates and returns a vector instruction that replaces the instructions in
- /// \p Bndl. \p Operands are the already vectorized operands.
- Value *createVectorInstr(ArrayRef<Value *> Bndl, ArrayRef<Value *> Operands);
- /// Erases all dead instructions from the dead instruction candidates
- /// collected during vectorization.
- void tryEraseDeadInstrs();
- /// Creates a shuffle instruction that shuffles \p VecOp according to \p Mask.
- /// \p UserBB is the block of the user bundle.
- Value *createShuffle(Value *VecOp, const ShuffleMask &Mask,
- BasicBlock *UserBB);
- /// Packs all elements of \p ToPack into a vector and returns that vector. \p
- /// UserBB is the block of the user bundle.
- Value *createPack(ArrayRef<Value *> ToPack, BasicBlock *UserBB);
- /// After we create vectors for groups of instructions, the original
- /// instructions are potentially dead and may need to be removed. This
- /// function helps collect these instructions (along with the pointer operands
- /// for loads/stores) so that they can be cleaned up later.
- void collectPotentiallyDeadInstrs(ArrayRef<Value *> Bndl);
-
- /// Helper class describing how(if) to vectorize the code.
- class ActionsVector {
- private:
- SmallVector<std::unique_ptr<Action>, 16> Actions;
-
- public:
- auto begin() const { return Actions.begin(); }
- auto end() const { return Actions.end(); }
- void push_back(std::unique_ptr<Action> &&ActPtr) {
- ActPtr->Idx = Actions.size();
- Actions.push_back(std::move(ActPtr));
- }
- void clear() { Actions.clear(); }
-#ifndef NDEBUG
- void print(raw_ostream &OS) const;
- void dump() const;
-#endif // NDEBUG
- };
- ActionsVector Actions;
- /// Helper counter for debugging. It counts the bundles that we attempt to
- /// vectorize in vectorizeRec().
- unsigned DebugBndlCnt = 0;
-
/// Recursively try to vectorize \p Bndl and its operands. This populates the
/// `Actions` vector.
Action *vectorizeRec(ArrayRef<Value *> Bndl, ArrayRef<Value *> UserBndl,
unsigned Depth, LegalityAnalysis &Legality);
- /// If the values in \p Bndl have external users, then emit unpacks and
- /// connect them to the users. \p Vec is the vectorized form of \p Bndl.
- void emitUnpacksForExternalUses(const ArrayRef<Value *> Bndl, Value *Vec);
/// Generate vector instructions based on `Actions` and return the last vector
/// created.
Value *emitVectors();
@@ -98,7 +46,7 @@ class LLVM_ABI BottomUpVec final : public RegionPass {
bool tryVectorize(ArrayRef<Value *> Seeds, LegalityAnalysis &Legality);
public:
- BottomUpVec() : RegionPass("bottom-up-vec") {}
+ BottomUpVec() : VecPassBase("bottom-up-vec") {}
bool runOnRegion(Region &Rgn, const Analyses &A) final;
};
diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TopDownVec.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TopDownVec.h
new file mode 100644
index 0000000000000..04ab0d7370f5f
--- /dev/null
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TopDownVec.h
@@ -0,0 +1,37 @@
+//===- TopDownVec.h ---------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// A Top-Down Vectorizer pass.
+//
+
+#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_TOPDOWNVEC_H
+#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_TOPDOWNVEC_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/Legality.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/VecPassBase.h"
+
+namespace llvm::sandboxir {
+
+class LLVM_ABI TopDownVec final : public VecPassBase {
+ unsigned long TopDownInvocationCnt = 0;
+
+ Action *vectorizeRec(ArrayRef<Value *> Bndl, unsigned Depth,
+ LegalityAnalysis &Legality);
+ Value *emitVectors();
+ bool tryVectorize(ArrayRef<Value *> Seeds, LegalityAnalysis &Legality);
+
+public:
+ TopDownVec() : VecPassBase("top-down-vec") {}
+ bool runOnRegion(Region &Rgn, const Analyses &A) final;
+};
+
+} // namespace llvm::sandboxir
+
+#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_TOPDOWNVEC_H
diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/VecPassBase.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/VecPassBase.h
new file mode 100644
index 0000000000000..cc8f441c67c53
--- /dev/null
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/VecPassBase.h
@@ -0,0 +1,121 @@
+//===- VecPassBase.h --------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Abstract base class shared by the top-down and bottom-up vectorizer passes.
+// Houses the common state (InstrMaps, dead-instruction bookkeeping, actions
+// list) and the utility functions used by both vectorizer passes.
+//
+
+#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_VECPASSBASE_H
+#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_VECPASSBASE_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/SandboxIR/Pass.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/InstrMaps.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/Legality.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h"
+
+namespace llvm::sandboxir {
+
+/// Abstract base class shared by TopDownVec and BottomUpVec.
+/// It owns the state common to both vectorizers and implements the utility
+/// functions used by both vectorizer passes.
+class LLVM_ABI VecPassBase : public RegionPass {
+protected:
+ /// Set to true whenever the pass emits vector code in the current region.
+ bool Change = false;
+ /// Scalar instructions that may be dead after vectorization.
+ DenseSet<Instruction *> DeadInstrCandidates;
+ /// Maps scalar values/instructions to their vector counterparts.
+ std::unique_ptr<InstrMaps> IMaps;
+ /// Helper counter for debugging — counts bundles attempted in vectorizeRec.
+ unsigned DebugBndlCnt = 0;
+
+ /// Ordered list of vectorization decisions produced by vectorizeRec.
+ class ActionsVector {
+ SmallVector<std::unique_ptr<Action>, 16> Actions;
+
+ public:
+ auto begin() const { return Actions.begin(); }
+ auto end() const { return Actions.end(); }
+ auto rbegin() const { return Actions.rbegin(); }
+ auto rend() const { return Actions.rend(); }
+ void push_back(std::unique_ptr<Action> &&ActPtr) {
+ ActPtr->Idx = Actions.size();
+ Actions.push_back(std::move(ActPtr));
+ }
+ void clear() { Actions.clear(); }
+#ifndef NDEBUG
+ void print(raw_ostream &OS) const;
+ LLVM_DUMP_METHOD void dump() const;
+#endif // NDEBUG
+ };
+ ActionsVector Actions;
+
+ explicit VecPassBase(StringRef Name) : RegionPass(Name) {}
+
+ // -----------------------------------------------------------------------
+ // Utility functions. These are owned by VecPassBase and accessible only
+ // to subclasses (TopDownVec and BottomUpVec) through inheritance.
+ // -----------------------------------------------------------------------
+
+ /// \Returns the operand at \p OpIdx for each instruction in \p Bndl.
+ static SmallVector<Value *, 4> getOperand(ArrayRef<Value *> Bndl,
+ unsigned OpIdx) {
+ SmallVector<Value *, 4> Operands;
+ for (Value *BndlV : Bndl)
+ Operands.push_back(cast<Instruction>(BndlV)->getOperand(OpIdx));
+ return Operands;
+ }
+
+ /// \Returns the BB iterator after the lowest instruction in \p Vals, or the
+ /// top of BB (after any PHIs) if no instruction is found in \p Vals.
+ static BasicBlock::iterator getInsertPointAfterInstrs(ArrayRef<Value *> Vals,
+ BasicBlock *BB) {
+ auto *BotI = VecUtils::getLastPHIOrSelf(VecUtils::getLowest(Vals, BB));
+ if (BotI == nullptr)
+ return BB->empty() ? BB->begin()
+ : std::next(VecUtils::getLastPHIOrSelf(&*BB->begin())
+ ->getIterator());
+ return std::next(BotI->getIterator());
+ }
+
+ /// Creates and returns a new vector instruction widening \p Bndl with
+ /// \p Operands as the vector operands.
+ static Value *createVectorInstr(ArrayRef<Value *> Bndl,
+ ArrayRef<Value *> Operands);
+
+ /// Creates a shuffle of \p VecOp according to \p Mask, inserted in \p UserBB.
+ static Value *createShuffle(Value *VecOp, const ShuffleMask &Mask,
+ BasicBlock *UserBB);
+
+ /// Packs all scalars/vectors in \p ToPack into a single vector, inserted in
+ /// \p UserBB.
+ static Value *createPack(ArrayRef<Value *> ToPack, BasicBlock *UserBB);
+
+ /// Adds the instructions in \p Bndl (and pointer operands of loads/stores)
+ /// to DeadInstrCandidates for later cleanup.
+ void collectPotentiallyDeadInstrs(ArrayRef<Value *> Bndl);
+
+ /// Erases all zero-use instructions from DeadInstrCandidates.
+ /// \p PassName is used as the debug-output prefix.
+ void tryEraseDeadInstrs(StringRef PassName);
+
+ /// For each element of \p Bndl that has external uses (users not yet
+ /// vectorized), emits extract instructions from \p Vec and replaces the
+ /// scalar uses with them.
+ void emitUnpacksForExternalUses(ArrayRef<Value *> Bndl, Value *Vec);
+};
+
+} // namespace llvm::sandboxir
+
+#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_PASSES_VECPASSBASE_H
diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h
index 99e411a1723b0..283b627879bfd 100644
--- a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h
@@ -12,6 +12,8 @@
#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_VECUTILS_H
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_VECUTILS_H
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/SandboxIR/Type.h"
@@ -33,6 +35,10 @@ template <> struct DenseMapInfo<SmallVector<sandboxir::Value *>> {
namespace sandboxir {
+class ShuffleMask;
+class InstrMaps;
+class VecPassBase;
+
class VecUtils {
public:
/// \Returns the number of elements in \p Ty. That is the number of lanes if a
@@ -379,7 +385,7 @@ class VecUtils {
}
#ifndef NDEBUG
- /// Helper dump function for debugging.
+ /// Print \p Bndl. Dump function for debugging.
LLVM_DUMP_METHOD static void dump(ArrayRef<Value *> Bndl);
LLVM_DUMP_METHOD static void dump(ArrayRef<Instruction *> Bndl);
#endif // NDEBUG
diff --git a/llvm/lib/Transforms/Vectorize/CMakeLists.txt b/llvm/lib/Transforms/Vectorize/CMakeLists.txt
index d081747b821a4..db68fa7cce885 100644
--- a/llvm/lib/Transforms/Vectorize/CMakeLists.txt
+++ b/llvm/lib/Transforms/Vectorize/CMakeLists.txt
@@ -9,11 +9,13 @@ add_llvm_component_library(LLVMVectorize
SandboxVectorizer/Interval.cpp
SandboxVectorizer/Legality.cpp
SandboxVectorizer/Passes/BottomUpVec.cpp
+ SandboxVectorizer/Passes/VecPassBase.cpp
SandboxVectorizer/Passes/LoadStoreVec.cpp
SandboxVectorizer/Passes/PackReuse.cpp
SandboxVectorizer/Passes/RegionsFromBBs.cpp
SandboxVectorizer/Passes/RegionsFromMetadata.cpp
SandboxVectorizer/Passes/SeedCollection.cpp
+ SandboxVectorizer/Passes/TopDownVec.cpp
SandboxVectorizer/Passes/TransactionAcceptOrRevert.cpp
SandboxVectorizer/Passes/TransactionSave.cpp
SandboxVectorizer/RegionWithScore.cpp
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
index 6bf257fcf8b1d..26e2f09d472e1 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
@@ -40,244 +40,6 @@ static cl::opt<unsigned long>
namespace sandboxir {
-static SmallVector<Value *, 4> getOperand(ArrayRef<Value *> Bndl,
- unsigned OpIdx) {
- SmallVector<Value *, 4> Operands;
- for (Value *BndlV : Bndl) {
- auto *BndlI = cast<Instruction>(BndlV);
- Operands.push_back(BndlI->getOperand(OpIdx));
- }
- return Operands;
-}
-
-/// \Returns the BB iterator after the lowest instruction in \p Vals, or the top
-/// of BB if no instruction found in \p Vals.
-static BasicBlock::iterator getInsertPointAfterInstrs(ArrayRef<Value *> Vals,
- BasicBlock *BB) {
- auto *BotI = VecUtils::getLastPHIOrSelf(VecUtils::getLowest(Vals, BB));
- if (BotI == nullptr)
- // We are using BB->begin() (or after PHIs) as the fallback insert point.
- return BB->empty()
- ? BB->begin()
- : std::next(
- VecUtils::getLastPHIOrSelf(&*BB->begin())->getIterator());
- return std::next(BotI->getIterator());
-}
-
-Value *BottomUpVec::createVectorInstr(ArrayRef<Value *> Bndl,
- ArrayRef<Value *> Operands) {
- auto CreateVectorInstr = [](ArrayRef<Value *> Bndl,
- ArrayRef<Value *> Operands) -> Value * {
- assert(all_of(Bndl, [](auto *V) { return isa<Instruction>(V); }) &&
- "Expect Instructions!");
- auto &Ctx = Bndl[0]->getContext();
-
- Type *ScalarTy = VecUtils::getElementType(Utils::getExpectedType(Bndl[0]));
- auto *VecTy = VecUtils::getWideType(ScalarTy, VecUtils::getNumLanes(Bndl));
-
- BasicBlock::iterator WhereIt = getInsertPointAfterInstrs(
- Bndl, cast<Instruction>(Bndl[0])->getParent());
-
- auto Opcode = cast<Instruction>(Bndl[0])->getOpcode();
- switch (Opcode) {
- case Instruction::Opcode::ZExt:
- case Instruction::Opcode::SExt:
- case Instruction::Opcode::FPToUI:
- case Instruction::Opcode::FPToSI:
- case Instruction::Opcode::FPExt:
- case Instruction::Opcode::PtrToInt:
- case Instruction::Opcode::IntToPtr:
- case Instruction::Opcode::SIToFP:
- case Instruction::Opcode::UIToFP:
- case Instruction::Opcode::Trunc:
- case Instruction::Opcode::FPTrunc:
- case Instruction::Opcode::BitCast: {
- assert(Operands.size() == 1u && "Casts are unary!");
- return CastInst::create(VecTy, Opcode, Operands[0], WhereIt, Ctx,
- "VCast");
- }
- case Instruction::Opcode::FCmp:
- case Instruction::Opcode::ICmp: {
- auto Pred = cast<CmpInst>(Bndl[0])->getPredicate();
- assert(all_of(drop_begin(Bndl),
- [Pred](auto *SBV) {
- return cast<CmpInst>(SBV)->getPredicate() == Pred;
- }) &&
- "Expected same predicate across bundle.");
- return CmpInst::create(Pred, Operands[0], Operands[1], WhereIt, Ctx,
- "VCmp");
- }
- case Instruction::Opcode::Select: {
- return SelectInst::create(Operands[0], Operands[1], Operands[2], WhereIt,
- Ctx, "Vec");
- }
- case Instruction::Opcode::FNeg: {
- auto *UOp0 = cast<UnaryOperator>(Bndl[0]);
- auto OpC = UOp0->getOpcode();
- return UnaryOperator::createWithCopiedFlags(OpC, Operands[0], UOp0,
- WhereIt, Ctx, "Vec");
- }
- case Instruction::Opcode::Add:
- case Instruction::Opcode::FAdd:
- case Instruction::Opcode::Sub:
- case Instruction::Opcode::FSub:
- case Instruction::Opcode::Mul:
- case Instruction::Opcode::FMul:
- case Instruction::Opcode::UDiv:
- case Instruction::Opcode::SDiv:
- case Instruction::Opcode::FDiv:
- case Instruction::Opcode::URem:
- case Instruction::Opcode::SRem:
- case Instruction::Opcode::FRem:
- case Instruction::Opcode::Shl:
- case Instruction::Opcode::LShr:
- case Instruction::Opcode::AShr:
- case Instruction::Opcode::And:
- case Instruction::Opcode::Or:
- case Instruction::Opcode::Xor: {
- auto *BinOp0 = cast<BinaryOperator>(Bndl[0]);
- auto *LHS = Operands[0];
- auto *RHS = Operands[1];
- return BinaryOperator::createWithCopiedFlags(
- BinOp0->getOpcode(), LHS, RHS, BinOp0, WhereIt, Ctx, "Vec");
- }
- case Instruction::Opcode::Load: {
- auto *Ld0 = cast<LoadInst>(Bndl[0]);
- Value *Ptr = Ld0->getPointerOperand();
- return LoadInst::create(VecTy, Ptr, Ld0->getAlign(), WhereIt, Ctx,
- "VecL");
- }
- case Instruction::Opcode::Store: {
- auto Align = cast<StoreInst>(Bndl[0])->getAlign();
- Value *Val = Operands[0];
- Value *Ptr = Operands[1];
- return StoreInst::create(Val, Ptr, Align, WhereIt, Ctx);
- }
- case Instruction::Opcode::UncondBr:
- case Instruction::Opcode::CondBr:
- case Instruction::Opcode::Ret:
- case Instruction::Opcode::PHI:
- case Instruction::Opcode::AddrSpaceCast:
- case Instruction::Opcode::Call:
- case Instruction::Opcode::GetElementPtr:
- llvm_unreachable("Unimplemented");
- break;
- default:
- llvm_unreachable("Unimplemented");
- break;
- }
- llvm_unreachable("Missing switch case!");
- // TODO: Propagate debug info.
- };
-
- auto *NewI = CreateVectorInstr(Bndl, Operands);
- LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "New instr: " << *NewI << "\n");
- return NewI;
-}
-
-void BottomUpVec::tryEraseDeadInstrs() {
- DenseMap<BasicBlock *, SmallVector<Instruction *>> SortedDeadInstrCandidates;
- // The dead instrs could span BBs, so we need to collect and sort them per BB.
- for (auto *DeadI : DeadInstrCandidates)
- SortedDeadInstrCandidates[DeadI->getParent()].push_back(DeadI);
- for (auto &Pair : SortedDeadInstrCandidates)
- sort(Pair.second,
- [](Instruction *I1, Instruction *I2) { return I1->comesBefore(I2); });
- for (const auto &Pair : SortedDeadInstrCandidates) {
- for (Instruction *I : reverse(Pair.second)) {
- if (I->hasNUses(0)) {
- // Erase the dead instructions bottom-to-top.
- LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Erase dead: " << *I << "\n");
- I-...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/205249
More information about the llvm-commits
mailing list