[llvm] 215e6be - [LV] Use MapVector for ScalarCostsTy for deterministic iter order (NFC)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 4 11:31:41 PDT 2025
Author: Florian Hahn
Date: 2025-08-04T19:31:07+01:00
New Revision: 215e6beae023341a8a17af1bd537472d16097e30
URL: https://github.com/llvm/llvm-project/commit/215e6beae023341a8a17af1bd537472d16097e30
DIFF: https://github.com/llvm/llvm-project/commit/215e6beae023341a8a17af1bd537472d16097e30.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index d04317bd8822d..13058a159cf95 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -1590,7 +1590,7 @@ class LoopVectorizationCostModel {
/// A type representing the costs for instructions if they were to be
/// scalarized rather than vectorized. The entries are Instruction-Cost
/// pairs.
- using ScalarCostsTy = DenseMap<Instruction *, InstructionCost>;
+ using ScalarCostsTy = MapVector<Instruction *, InstructionCost>;
/// A set containing all BasicBlocks that are known to present after
/// vectorization as a predicated block.
@@ -4992,7 +4992,8 @@ void LoopVectorizationCostModel::collectInstsToScalarize(ElementCount VF) {
if (!isScalarAfterVectorization(&I, VF) && !VF.isScalable() &&
!useEmulatedMaskMemRefHack(&I, VF) &&
computePredInstDiscount(&I, ScalarCosts, VF) >= 0) {
- ScalarCostsVF.insert_range(ScalarCosts);
+ for (const auto &[I, IC] : ScalarCosts)
+ ScalarCostsVF.insert({I, IC});
// Check if we decided to scalarize a call. If so, update the widening
// decision of the call to CM_Scalarize with the computed scalar cost.
for (const auto &[I, Cost] : ScalarCosts) {
More information about the llvm-commits
mailing list