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