aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorvporpo <vporpodas@google.com>2025-01-23 15:08:13 -0800
committerGitHub <noreply@github.com>2025-01-23 15:08:13 -0800
commitc7053ac202de1723c49d2f02d1c56d7a0a4481c0 (patch)
tree858b5d08aa4ef61319eaf407707e5d93f4dabbd2 /llvm/lib
parent621e5cd8204596874c2ec7c8c169044d8e6865e3 (diff)
downloadllvm-c7053ac202de1723c49d2f02d1c56d7a0a4481c0.zip
llvm-c7053ac202de1723c49d2f02d1c56d7a0a4481c0.tar.gz
llvm-c7053ac202de1723c49d2f02d1c56d7a0a4481c0.tar.bz2
[SandboxVec][BottomUpVec] Disable crossing BBs (#124039)
Crossing BBs is not currently supported by the structures of the vectorizer. This patch fixes instances where this was happening, including: - a walk of use-def operands that updates the UnscheduledSuccs counter, - the dead instruction removal is now done per BB, - the scheduler, which will reject bundles that cross BBs.
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.cpp3
-rw-r--r--llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp21
-rw-r--r--llvm/lib/Transforms/Vectorize/SandboxVectorizer/Scheduler.cpp7
3 files changed, 23 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.cpp
index d65a04c..f080111 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.cpp
@@ -232,6 +232,9 @@ void DependencyGraph::setDefUseUnscheduledSuccs(
auto *OpI = dyn_cast<Instruction>(Op);
if (OpI == nullptr)
continue;
+ // TODO: For now don't cross BBs.
+ if (OpI->getParent() != I.getParent())
+ continue;
if (!NewInterval.contains(OpI))
continue;
auto *OpN = getNode(OpI);
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
index 18c3b37..06a1769 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
@@ -169,14 +169,19 @@ Value *BottomUpVec::createVectorInstr(ArrayRef<Value *> Bndl,
}
void BottomUpVec::tryEraseDeadInstrs() {
- // Visiting the dead instructions bottom-to-top.
- SmallVector<Instruction *> SortedDeadInstrCandidates(
- DeadInstrCandidates.begin(), DeadInstrCandidates.end());
- sort(SortedDeadInstrCandidates,
- [](Instruction *I1, Instruction *I2) { return I1->comesBefore(I2); });
- for (Instruction *I : reverse(SortedDeadInstrCandidates)) {
- if (I->hasNUses(0))
- I->eraseFromParent();
+ 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.
+ I->eraseFromParent();
+ }
}
DeadInstrCandidates.clear();
}
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Scheduler.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Scheduler.cpp
index f9cdbe8..496521b 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Scheduler.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Scheduler.cpp
@@ -206,6 +206,13 @@ bool Scheduler::trySchedule(ArrayRef<Instruction *> Instrs) {
// We start scheduling at the bottom instr of Instrs.
ScheduleTopItOpt = std::next(VecUtils::getLowest(Instrs)->getIterator());
+ // TODO: For now don't cross BBs.
+ if (!DAG.getInterval().empty()) {
+ auto *BB = DAG.getInterval().top()->getParent();
+ if (any_of(Instrs, [BB](auto *I) { return I->getParent() != BB; }))
+ return false;
+ }
+
// Extend the DAG to include Instrs.
Interval<Instruction> Extension = DAG.extend(Instrs);
// Add nodes to ready list.