[PATCH] D148966: [SLP] Cleanup: Remove loop around `tryToVectorizeSequence` of PHIs.
Vasileios Porpodas via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 21 15:08:56 PDT 2023
vporpo created this revision.
vporpo added a reviewer: ABataev.
Herald added a subscriber: hiraditya.
Herald added a project: All.
vporpo requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead.
Herald added a project: LLVM.
I think that the loop is not needed.
I added an assertion to check whether a second iteration succeeds in
vectorizing phi noeds, but it never caused a crash.
Anyway, if this is actually used, we don't have a test for it.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D148966
Files:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -14501,53 +14501,50 @@
};
bool HaveVectorizedPhiNodes = false;
- do {
- // Collect the incoming values from the PHIs.
- Incoming.clear();
- for (Instruction &I : *BB) {
- PHINode *P = dyn_cast<PHINode>(&I);
- if (!P)
- break;
+ // Collect the incoming values from the PHIs.
+ Incoming.clear();
+ for (Instruction &I : *BB) {
+ PHINode *P = dyn_cast<PHINode>(&I);
+ if (!P)
+ break;
- // No need to analyze deleted, vectorized and non-vectorizable
- // instructions.
- if (!VisitedInstrs.count(P) && !R.isDeleted(P) &&
- isValidElementType(P->getType()))
- Incoming.push_back(P);
- }
+ // No need to analyze deleted, vectorized and non-vectorizable
+ // instructions.
+ if (!VisitedInstrs.count(P) && !R.isDeleted(P) &&
+ isValidElementType(P->getType()))
+ Incoming.push_back(P);
+ }
- // Find the corresponding non-phi nodes for better matching when trying to
- // build the tree.
- for (Value *V : Incoming) {
- SmallVectorImpl<Value *> &Opcodes =
- PHIToOpcodes.try_emplace(V).first->getSecond();
- if (!Opcodes.empty())
+ // Find the corresponding non-phi nodes for better matching when trying to
+ // build the tree.
+ for (Value *V : Incoming) {
+ SmallVectorImpl<Value *> &Opcodes =
+ PHIToOpcodes.try_emplace(V).first->getSecond();
+ if (!Opcodes.empty())
+ continue;
+ SmallVector<Value *, 4> Nodes(1, V);
+ SmallPtrSet<Value *, 4> Visited;
+ while (!Nodes.empty()) {
+ auto *PHI = cast<PHINode>(Nodes.pop_back_val());
+ if (!Visited.insert(PHI).second)
continue;
- SmallVector<Value *, 4> Nodes(1, V);
- SmallPtrSet<Value *, 4> Visited;
- while (!Nodes.empty()) {
- auto *PHI = cast<PHINode>(Nodes.pop_back_val());
- if (!Visited.insert(PHI).second)
+ for (Value *V : PHI->incoming_values()) {
+ if (auto *PHI1 = dyn_cast<PHINode>((V))) {
+ Nodes.push_back(PHI1);
continue;
- for (Value *V : PHI->incoming_values()) {
- if (auto *PHI1 = dyn_cast<PHINode>((V))) {
- Nodes.push_back(PHI1);
- continue;
- }
- Opcodes.emplace_back(V);
}
+ Opcodes.emplace_back(V);
}
}
+ }
- HaveVectorizedPhiNodes = tryToVectorizeSequence<Value>(
- Incoming, PHICompare, AreCompatiblePHIs,
- [this, &R](ArrayRef<Value *> Candidates, bool LimitForRegisterSize) {
- return tryToVectorizeList(Candidates, R, LimitForRegisterSize);
- },
- /*LimitForRegisterSize=*/true, R);
- Changed |= HaveVectorizedPhiNodes;
- VisitedInstrs.insert(Incoming.begin(), Incoming.end());
- } while (HaveVectorizedPhiNodes);
+ HaveVectorizedPhiNodes = tryToVectorizeSequence<Value>(
+ Incoming, PHICompare, AreCompatiblePHIs,
+ [this, &R](ArrayRef<Value *> Candidates, bool LimitForRegisterSize) {
+ return tryToVectorizeList(Candidates, R, LimitForRegisterSize);
+ },
+ /*LimitForRegisterSize=*/true, R);
+ Changed |= HaveVectorizedPhiNodes;
VisitedInstrs.clear();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148966.515928.patch
Type: text/x-patch
Size: 3378 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230421/51c8ecdf/attachment.bin>
More information about the llvm-commits
mailing list