@@ -304,6 +304,7 @@ class BoUpSLP {
304
304
typedef SmallVector<Instruction *, 16 > InstrList;
305
305
typedef SmallPtrSet<Value *, 16 > ValueSet;
306
306
typedef SmallVector<StoreInst *, 8 > StoreList;
307
+ typedef MapVector<Value *, std::vector<DebugLoc>> ExtraValueToDebugLocsMap;
307
308
308
309
BoUpSLP (Function *Func, ScalarEvolution *Se, TargetTransformInfo *Tti,
309
310
TargetLibraryInfo *TLi, AliasAnalysis *Aa, LoopInfo *Li,
@@ -333,7 +334,7 @@ class BoUpSLP {
333
334
// / Vectorize the tree but with the list of externally used values \p
334
335
// / ExternallyUsedValues. Values in this MapVector can be replaced but the
335
336
// / generated extractvalue instructions.
336
- Value *vectorizeTree (MapVector<Value *, DebugLoc> &ExternallyUsedValues);
337
+ Value *vectorizeTree (ExtraValueToDebugLocsMap &ExternallyUsedValues);
337
338
338
339
// / \returns the cost incurred by unwanted spills and fills, caused by
339
340
// / holding live values over call sites.
@@ -352,7 +353,7 @@ class BoUpSLP {
352
353
// / into account (anf updating it, if required) list of externally used
353
354
// / values stored in \p ExternallyUsedValues.
354
355
void buildTree (ArrayRef<Value *> Roots,
355
- MapVector<Value *, DebugLoc> &ExternallyUsedValues,
356
+ ExtraValueToDebugLocsMap &ExternallyUsedValues,
356
357
ArrayRef<Value *> UserIgnoreLst = None);
357
358
358
359
// / Clear the internal data structures that are created by 'buildTree'.
@@ -953,11 +954,11 @@ class BoUpSLP {
953
954
954
955
void BoUpSLP::buildTree (ArrayRef<Value *> Roots,
955
956
ArrayRef<Value *> UserIgnoreLst) {
956
- MapVector<Value *, DebugLoc> ExternallyUsedValues;
957
+ ExtraValueToDebugLocsMap ExternallyUsedValues;
957
958
buildTree (Roots, ExternallyUsedValues, UserIgnoreLst);
958
959
}
959
960
void BoUpSLP::buildTree (ArrayRef<Value *> Roots,
960
- MapVector<Value *, DebugLoc> &ExternallyUsedValues,
961
+ ExtraValueToDebugLocsMap &ExternallyUsedValues,
961
962
ArrayRef<Value *> UserIgnoreLst) {
962
963
deleteTree ();
963
964
UserIgnoreList = UserIgnoreLst;
@@ -2801,12 +2802,12 @@ Value *BoUpSLP::vectorizeTree(ArrayRef<Value *> VL, TreeEntry *E) {
2801
2802
}
2802
2803
2803
2804
Value *BoUpSLP::vectorizeTree () {
2804
- MapVector<Value *, DebugLoc> ExternallyUsedValues;
2805
+ ExtraValueToDebugLocsMap ExternallyUsedValues;
2805
2806
return vectorizeTree (ExternallyUsedValues);
2806
2807
}
2807
2808
2808
2809
Value *
2809
- BoUpSLP::vectorizeTree (MapVector<Value *, DebugLoc> &ExternallyUsedValues) {
2810
+ BoUpSLP::vectorizeTree (ExtraValueToDebugLocsMap &ExternallyUsedValues) {
2810
2811
2811
2812
// All blocks must be scheduled before any instructions are inserted.
2812
2813
for (auto &BSIter : BlocksSchedules) {
@@ -2868,7 +2869,6 @@ BoUpSLP::vectorizeTree(MapVector<Value *, DebugLoc> &ExternallyUsedValues) {
2868
2869
assert (ExternallyUsedValues.count (Scalar) &&
2869
2870
" Scalar with nullptr as an external user must be registered in "
2870
2871
" ExternallyUsedValues map" );
2871
- DebugLoc DL = ExternallyUsedValues[Scalar];
2872
2872
if (auto *VecI = dyn_cast<Instruction>(Vec)) {
2873
2873
Builder.SetInsertPoint (VecI->getParent (),
2874
2874
std::next (VecI->getIterator ()));
@@ -2878,8 +2878,8 @@ BoUpSLP::vectorizeTree(MapVector<Value *, DebugLoc> &ExternallyUsedValues) {
2878
2878
Value *Ex = Builder.CreateExtractElement (Vec, Lane);
2879
2879
Ex = extend (ScalarRoot, Ex, Scalar->getType ());
2880
2880
CSEBlocks.insert (cast<Instruction>(Scalar)->getParent ());
2881
+ ExternallyUsedValues[Ex] = ExternallyUsedValues[Scalar];
2881
2882
ExternallyUsedValues.erase (Scalar);
2882
- ExternallyUsedValues[Ex] = DL;
2883
2883
continue ;
2884
2884
}
2885
2885
@@ -4439,9 +4439,11 @@ class HorizontalReduction {
4439
4439
Builder.setFastMathFlags (Unsafe);
4440
4440
unsigned i = 0 ;
4441
4441
4442
- MapVector<Value *, DebugLoc> ExternallyUsedValues;
4442
+ BoUpSLP::ExtraValueToDebugLocsMap ExternallyUsedValues;
4443
+ // The same extra argument may be used several time, so log each attempt
4444
+ // to use it.
4443
4445
for (auto &Pair : ExtraArgs)
4444
- ExternallyUsedValues[Pair.second ] = Pair.first ->getDebugLoc ();
4446
+ ExternallyUsedValues[Pair.second ]. push_back ( Pair.first ->getDebugLoc () );
4445
4447
while (i < NumReducedVals - ReduxWidth + 1 && ReduxWidth > 2 ) {
4446
4448
auto VL = makeArrayRef (&ReducedVals[i], ReduxWidth);
4447
4449
V.buildTree (VL, ExternallyUsedValues, ReductionOps);
@@ -4489,9 +4491,12 @@ class HorizontalReduction {
4489
4491
Builder.CreateBinOp (ReductionOpcode, VectorizedTree, I);
4490
4492
}
4491
4493
for (auto &Pair : ExternallyUsedValues) {
4492
- Builder.SetCurrentDebugLocation (Pair.second );
4493
- VectorizedTree = Builder.CreateBinOp (ReductionOpcode, VectorizedTree,
4494
- Pair.first , " bin.extra" );
4494
+ // Add each externally used value to the final reduction.
4495
+ for (auto &DL : Pair.second ) {
4496
+ Builder.SetCurrentDebugLocation (DL);
4497
+ VectorizedTree = Builder.CreateBinOp (ReductionOpcode, VectorizedTree,
4498
+ Pair.first , " bin.extra" );
4499
+ }
4495
4500
}
4496
4501
// Update users.
4497
4502
if (ReductionPHI && !isa<UndefValue>(ReductionPHI)) {
0 commit comments