@@ -17778,10 +17778,12 @@ class HorizontalReduction {
1777817778 // Emit code for constant values.
1777917779 if (Candidates.size() > 1 && allConstant(Candidates)) {
1778017780 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();
1778217783 for (Value *VC : ArrayRef(Candidates).drop_front()) {
1778317784 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();
1778517787 if (auto *ResI = dyn_cast<Instruction>(Res))
1778617788 V.analyzedReductionRoot(ResI);
1778717789 }
@@ -17802,8 +17804,10 @@ class HorizontalReduction {
1780217804 // Gather same values.
1780317805 MapVector<Value *, unsigned> SameValuesCounter;
1780417806 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+ }
1780717811 // Used to check if the reduced values used same number of times. In this
1780817812 // case the compiler may produce better code. E.g. if reduced values are
1780917813 // aabbccdd (8 x values), then the first node of the tree will have a node
@@ -17827,12 +17831,12 @@ class HorizontalReduction {
1782717831 });
1782817832 Candidates.resize(SameValuesCounter.size());
1782917833 transform(SameValuesCounter, Candidates.begin(),
17830- [](const auto &P) { return P.first; });
17834+ [& ](const auto &P) { return TrackedVals.at( P.first) ; });
1783117835 NumReducedVals = Candidates.size();
1783217836 // Have a reduction of the same element.
1783317837 if (NumReducedVals == 1) {
1783417838 Value *OrigV = TrackedToOrig.find(Candidates.front())->second;
17835- unsigned Cnt = SameValuesCounter.lookup (OrigV);
17839+ unsigned Cnt = SameValuesCounter.find (OrigV)->second ;
1783617840 Value *RedVal =
1783717841 emitScaleForReusedOps(Candidates.front(), Builder, Cnt);
1783817842 VectorizedTree = GetNewVectorizedTree(VectorizedTree, RedVal);
@@ -17937,7 +17941,7 @@ class HorizontalReduction {
1793717941 continue;
1793817942 Value *V = Candidates[Cnt];
1793917943 Value *OrigV = TrackedToOrig.find(V)->second;
17940- ++SameValuesCounter[ OrigV] ;
17944+ ++SameValuesCounter.find( OrigV)->second ;
1794117945 }
1794217946 }
1794317947 SmallPtrSet<Value *, 4> VLScalars(VL.begin(), VL.end());
@@ -17956,8 +17960,8 @@ class HorizontalReduction {
1795617960 continue;
1795717961 }
1795817962 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 ;
1796117965 if (NumOps != ReducedValsToOps.find(OrigV)->second.size())
1796217966 LocalExternallyUsedValues[RdxVal];
1796317967 }
@@ -18085,10 +18089,11 @@ class HorizontalReduction {
1808518089 for (Value *RdxVal : VL) {
1808618090 Value *OrigV = TrackedToOrig.find(RdxVal)->second;
1808718091 if (IsSupportedHorRdxIdentityOp) {
18088- VectorizedVals.try_emplace(OrigV, SameValuesCounter[RdxVal]);
18092+ VectorizedVals.try_emplace(OrigV,
18093+ SameValuesCounter.find(OrigV)->second);
1808918094 continue;
1809018095 }
18091- ++VectorizedVals.try_emplace(OrigV, 0 ).first->getSecond();
18096+ ++VectorizedVals.try_emplace(OrigV).first->getSecond();
1809218097 if (!V.isVectorized(RdxVal))
1809318098 RequiredExtract.insert(RdxVal);
1809418099 }
@@ -18099,10 +18104,10 @@ class HorizontalReduction {
1809918104 }
1810018105 if (OptReusedScalars && !AnyVectorized) {
1810118106 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);
1810318109 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);
1810618111 }
1810718112 continue;
1810818113 }
0 commit comments