Skip to content

Commit

Permalink
[SLP] Avoid repeated visitation in getVectorElementSize(); NFC
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Mar 22, 2020
1 parent c1bc56b commit a63eaa5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Expand Up @@ -5308,16 +5308,17 @@ unsigned BoUpSLP::getVectorElementSize(Value *V) const {
// of memory operations where possible.
SmallVector<Instruction *, 16> Worklist;
SmallPtrSet<Instruction *, 16> Visited;
if (auto *I = dyn_cast<Instruction>(V))
if (auto *I = dyn_cast<Instruction>(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.
auto MaxWidth = 0u;
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.
Expand All @@ -5337,7 +5338,7 @@ unsigned BoUpSLP::getVectorElementSize(Value *V) const {
isa<CmpInst>(I) || isa<SelectInst>(I) || isa<BinaryOperator>(I)) {
for (Use &U : I->operands())
if (auto *J = dyn_cast<Instruction>(U.get()))
if (!Visited.count(J))
if (Visited.insert(J).second)
Worklist.push_back(J);
}

Expand Down

0 comments on commit a63eaa5

Please sign in to comment.