@@ -17778,12 +17778,10 @@ class HorizontalReduction {
17778
17778
// Emit code for constant values.
17779
17779
if (Candidates.size() > 1 && allConstant(Candidates)) {
17780
17780
Value *Res = Candidates.front();
17781
- Value *OrigV = TrackedToOrig.find(Candidates.front())->second;
17782
- ++VectorizedVals.try_emplace(OrigV).first->getSecond();
17781
+ ++VectorizedVals.try_emplace(Candidates.front(), 0).first->getSecond();
17783
17782
for (Value *VC : ArrayRef(Candidates).drop_front()) {
17784
17783
Res = createOp(Builder, RdxKind, Res, VC, "const.rdx", ReductionOps);
17785
- Value *OrigV = TrackedToOrig.find(VC)->second;
17786
- ++VectorizedVals.try_emplace(OrigV).first->getSecond();
17784
+ ++VectorizedVals.try_emplace(VC, 0).first->getSecond();
17787
17785
if (auto *ResI = dyn_cast<Instruction>(Res))
17788
17786
V.analyzedReductionRoot(ResI);
17789
17787
}
@@ -17804,10 +17802,8 @@ class HorizontalReduction {
17804
17802
// Gather same values.
17805
17803
MapVector<Value *, unsigned> SameValuesCounter;
17806
17804
if (IsSupportedHorRdxIdentityOp)
17807
- for (Value *V : Candidates) {
17808
- Value *OrigV = TrackedToOrig.find(V)->second;
17809
- ++SameValuesCounter.try_emplace(OrigV).first->second;
17810
- }
17805
+ for (Value *V : Candidates)
17806
+ ++SameValuesCounter.insert(std::make_pair(V, 0)).first->second;
17811
17807
// Used to check if the reduced values used same number of times. In this
17812
17808
// case the compiler may produce better code. E.g. if reduced values are
17813
17809
// aabbccdd (8 x values), then the first node of the tree will have a node
@@ -17831,12 +17827,12 @@ class HorizontalReduction {
17831
17827
});
17832
17828
Candidates.resize(SameValuesCounter.size());
17833
17829
transform(SameValuesCounter, Candidates.begin(),
17834
- [& ](const auto &P) { return TrackedVals.at( P.first) ; });
17830
+ [](const auto &P) { return P.first; });
17835
17831
NumReducedVals = Candidates.size();
17836
17832
// Have a reduction of the same element.
17837
17833
if (NumReducedVals == 1) {
17838
17834
Value *OrigV = TrackedToOrig.find(Candidates.front())->second;
17839
- unsigned Cnt = SameValuesCounter.find (OrigV)->second ;
17835
+ unsigned Cnt = SameValuesCounter.lookup (OrigV);
17840
17836
Value *RedVal =
17841
17837
emitScaleForReusedOps(Candidates.front(), Builder, Cnt);
17842
17838
VectorizedTree = GetNewVectorizedTree(VectorizedTree, RedVal);
@@ -17941,7 +17937,7 @@ class HorizontalReduction {
17941
17937
continue;
17942
17938
Value *V = Candidates[Cnt];
17943
17939
Value *OrigV = TrackedToOrig.find(V)->second;
17944
- ++SameValuesCounter.find( OrigV)->second ;
17940
+ ++SameValuesCounter[ OrigV] ;
17945
17941
}
17946
17942
}
17947
17943
SmallPtrSet<Value *, 4> VLScalars(VL.begin(), VL.end());
@@ -17960,8 +17956,8 @@ class HorizontalReduction {
17960
17956
continue;
17961
17957
}
17962
17958
Value *OrigV = TrackedToOrig.find(RdxVal)->second;
17963
- unsigned NumOps = VectorizedVals.lookup(OrigV) +
17964
- SameValuesCounter.find( OrigV)->second ;
17959
+ unsigned NumOps =
17960
+ VectorizedVals.lookup(RdxVal) + SameValuesCounter[ OrigV] ;
17965
17961
if (NumOps != ReducedValsToOps.find(OrigV)->second.size())
17966
17962
LocalExternallyUsedValues[RdxVal];
17967
17963
}
@@ -18089,11 +18085,10 @@ class HorizontalReduction {
18089
18085
for (Value *RdxVal : VL) {
18090
18086
Value *OrigV = TrackedToOrig.find(RdxVal)->second;
18091
18087
if (IsSupportedHorRdxIdentityOp) {
18092
- VectorizedVals.try_emplace(OrigV,
18093
- SameValuesCounter.find(OrigV)->second);
18088
+ VectorizedVals.try_emplace(OrigV, SameValuesCounter[RdxVal]);
18094
18089
continue;
18095
18090
}
18096
- ++VectorizedVals.try_emplace(OrigV).first->getSecond();
18091
+ ++VectorizedVals.try_emplace(OrigV, 0 ).first->getSecond();
18097
18092
if (!V.isVectorized(RdxVal))
18098
18093
RequiredExtract.insert(RdxVal);
18099
18094
}
@@ -18104,10 +18099,10 @@ class HorizontalReduction {
18104
18099
}
18105
18100
if (OptReusedScalars && !AnyVectorized) {
18106
18101
for (const std::pair<Value *, unsigned> &P : SameValuesCounter) {
18107
- Value *RdxVal = TrackedVals.find(P.first)->second;
18108
- Value *RedVal = emitScaleForReusedOps(RdxVal, Builder, P.second);
18102
+ Value *RedVal = emitScaleForReusedOps(P.first, Builder, P.second);
18109
18103
VectorizedTree = GetNewVectorizedTree(VectorizedTree, RedVal);
18110
- VectorizedVals.try_emplace(P.first, P.second);
18104
+ Value *OrigV = TrackedToOrig.find(P.first)->second;
18105
+ VectorizedVals.try_emplace(OrigV, P.second);
18111
18106
}
18112
18107
continue;
18113
18108
}
0 commit comments