Skip to content

Commit 246b46c

Browse files
committed
[LV] Use MapVector for ScalarCostsTy for deterministic iter order (NFC)
We iterate over the scalar costs of instruction when printing costs, and currently the iteration order is not deterministic. Currently no tests check the output with multiple instructions in the map, but those will come soon.
1 parent 74519ed commit 246b46c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ class LoopVectorizationCostModel {
15621562
/// A type representing the costs for instructions if they were to be
15631563
/// scalarized rather than vectorized. The entries are Instruction-Cost
15641564
/// pairs.
1565-
using ScalarCostsTy = DenseMap<Instruction *, InstructionCost>;
1565+
using ScalarCostsTy = MapVector<Instruction *, InstructionCost>;
15661566

15671567
/// A set containing all BasicBlocks that are known to present after
15681568
/// vectorization as a predicated block.
@@ -4925,7 +4925,8 @@ void LoopVectorizationCostModel::collectInstsToScalarize(ElementCount VF) {
49254925
if (!isScalarAfterVectorization(&I, VF) && !VF.isScalable() &&
49264926
!useEmulatedMaskMemRefHack(&I, VF) &&
49274927
computePredInstDiscount(&I, ScalarCosts, VF) >= 0) {
4928-
ScalarCostsVF.insert_range(ScalarCosts);
4928+
for (const auto &[I, IC] : ScalarCosts)
4929+
ScalarCostsVF.insert({I, IC});
49294930
// Check if we decided to scalarize a call. If so, update the widening
49304931
// decision of the call to CM_Scalarize with the computed scalar cost.
49314932
for (const auto &[I, Cost] : ScalarCosts) {

0 commit comments

Comments
 (0)