From a63eaa5449fac237d492bd725a88fabf39881dc2 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 21 Mar 2020 12:45:51 +0100 Subject: [PATCH] [SLP] Avoid repeated visitation in getVectorElementSize(); NFC We need to insert into the Visited set at the same time we insert into the worklist. Otherwise we may end up pushing the same instruction to the worklist multiple times, and only adding it to the visited set later. --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 377aa78730b04..53678bc97d7ed 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -5308,8 +5308,10 @@ unsigned BoUpSLP::getVectorElementSize(Value *V) const { // of memory operations where possible. SmallVector Worklist; SmallPtrSet Visited; - if (auto *I = dyn_cast(V)) + if (auto *I = dyn_cast(V)) { Worklist.push_back(I); + Visited.insert(I); + } // Traverse the expression tree in bottom-up order looking for loads. If we // encounter an instruction we don't yet handle, we give up. @@ -5317,7 +5319,6 @@ unsigned BoUpSLP::getVectorElementSize(Value *V) const { auto FoundUnknownInst = false; while (!Worklist.empty() && !FoundUnknownInst) { auto *I = Worklist.pop_back_val(); - Visited.insert(I); // We should only be looking at scalar instructions here. If the current // instruction has a vector type, give up. @@ -5337,7 +5338,7 @@ unsigned BoUpSLP::getVectorElementSize(Value *V) const { isa(I) || isa(I) || isa(I)) { for (Use &U : I->operands()) if (auto *J = dyn_cast(U.get())) - if (!Visited.count(J)) + if (Visited.insert(J).second) Worklist.push_back(J); }