Skip to content

Commit d139a47

Browse files
committed
[VectorUtils] Improve computeMinimumValueSizes (NFC)
The Worklist used by computeMinimumValueSizes is wastefully a Value-vector, when the top of the loop attempts to cast the popped value to an Instruction anyway. Improve the algorithm by cutting this wasteful work, refining the type of Worklist, Visited, and Roots from Value-vectors to Instruction-vectors.
1 parent 8639b36 commit d139a47

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,9 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
750750
// to ensure no extra casts would need to be inserted, so every DAG
751751
// of connected values must have the same minimum bitwidth.
752752
EquivalenceClasses<Value *> ECs;
753-
SmallVector<Value *, 16> Worklist;
754-
SmallPtrSet<Value *, 4> Roots;
755-
SmallPtrSet<Value *, 16> Visited;
753+
SmallVector<Instruction *, 16> Worklist;
754+
SmallPtrSet<Instruction *, 4> Roots;
755+
SmallPtrSet<Instruction *, 16> Visited;
756756
DenseMap<Value *, uint64_t> DBits;
757757
SmallPtrSet<Instruction *, 4> InstructionSet;
758758
MapVector<Instruction *, uint64_t> MinBWs;
@@ -786,17 +786,12 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
786786

787787
// Now proceed breadth-first, unioning values together.
788788
while (!Worklist.empty()) {
789-
Value *Val = Worklist.pop_back_val();
790-
Value *Leader = ECs.getOrInsertLeaderValue(Val);
789+
Instruction *I = Worklist.pop_back_val();
790+
Value *Leader = ECs.getOrInsertLeaderValue(I);
791791

792-
if (!Visited.insert(Val).second)
792+
if (!Visited.insert(I).second)
793793
continue;
794794

795-
// Non-instructions terminate a chain successfully.
796-
if (!isa<Instruction>(Val))
797-
continue;
798-
Instruction *I = cast<Instruction>(Val);
799-
800795
// If we encounter a type that is larger than 64 bits, we can't represent
801796
// it so bail out.
802797
if (DB.getDemandedBits(I).getBitWidth() > 64)
@@ -831,9 +826,10 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
831826
// All bits demanded, no point continuing.
832827
continue;
833828

834-
for (Value *O : cast<User>(I)->operands()) {
829+
for (Value *O : I->operands()) {
835830
ECs.unionSets(Leader, O);
836-
Worklist.push_back(O);
831+
if (auto *OI = dyn_cast<Instruction>(O))
832+
Worklist.push_back(OI);
837833
}
838834
}
839835

@@ -874,7 +870,7 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB,
874870
if (!MI)
875871
continue;
876872
Type *Ty = M->getType();
877-
if (Roots.count(M))
873+
if (Roots.count(MI))
878874
Ty = MI->getOperand(0)->getType();
879875

880876
if (MinBW >= Ty->getScalarSizeInBits())

0 commit comments

Comments
 (0)