Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 8188e22

Browse files
committed
Revert "[SLP] Fix for PR32036: Vectorized horizontal reduction returning wrong"
This reverts commit 7c5141e577d9efd1c8e3087566a38ce6b3a41a84. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295957 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 4ef753a commit 8188e22

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ class BoUpSLP {
304304
typedef SmallVector<Instruction *, 16> InstrList;
305305
typedef SmallPtrSet<Value *, 16> ValueSet;
306306
typedef SmallVector<StoreInst *, 8> StoreList;
307-
typedef MapVector<Value *, SmallVector<DebugLoc, 4>> ExtraValueToDebugLocsMap;
308307

309308
BoUpSLP(Function *Func, ScalarEvolution *Se, TargetTransformInfo *Tti,
310309
TargetLibraryInfo *TLi, AliasAnalysis *Aa, LoopInfo *Li,
@@ -334,7 +333,7 @@ class BoUpSLP {
334333
/// Vectorize the tree but with the list of externally used values \p
335334
/// ExternallyUsedValues. Values in this MapVector can be replaced but the
336335
/// generated extractvalue instructions.
337-
Value *vectorizeTree(ExtraValueToDebugLocsMap &ExternallyUsedValues);
336+
Value *vectorizeTree(MapVector<Value *, DebugLoc> &ExternallyUsedValues);
338337

339338
/// \returns the cost incurred by unwanted spills and fills, caused by
340339
/// holding live values over call sites.
@@ -353,7 +352,7 @@ class BoUpSLP {
353352
/// into account (anf updating it, if required) list of externally used
354353
/// values stored in \p ExternallyUsedValues.
355354
void buildTree(ArrayRef<Value *> Roots,
356-
ExtraValueToDebugLocsMap &ExternallyUsedValues,
355+
MapVector<Value *, DebugLoc> &ExternallyUsedValues,
357356
ArrayRef<Value *> UserIgnoreLst = None);
358357

359358
/// Clear the internal data structures that are created by 'buildTree'.
@@ -954,11 +953,11 @@ class BoUpSLP {
954953

955954
void BoUpSLP::buildTree(ArrayRef<Value *> Roots,
956955
ArrayRef<Value *> UserIgnoreLst) {
957-
ExtraValueToDebugLocsMap ExternallyUsedValues;
956+
MapVector<Value *, DebugLoc> ExternallyUsedValues;
958957
buildTree(Roots, ExternallyUsedValues, UserIgnoreLst);
959958
}
960959
void BoUpSLP::buildTree(ArrayRef<Value *> Roots,
961-
ExtraValueToDebugLocsMap &ExternallyUsedValues,
960+
MapVector<Value *, DebugLoc> &ExternallyUsedValues,
962961
ArrayRef<Value *> UserIgnoreLst) {
963962
deleteTree();
964963
UserIgnoreList = UserIgnoreLst;
@@ -2802,12 +2801,12 @@ Value *BoUpSLP::vectorizeTree(ArrayRef<Value *> VL, TreeEntry *E) {
28022801
}
28032802

28042803
Value *BoUpSLP::vectorizeTree() {
2805-
ExtraValueToDebugLocsMap ExternallyUsedValues;
2804+
MapVector<Value *, DebugLoc> ExternallyUsedValues;
28062805
return vectorizeTree(ExternallyUsedValues);
28072806
}
28082807

28092808
Value *
2810-
BoUpSLP::vectorizeTree(ExtraValueToDebugLocsMap &ExternallyUsedValues) {
2809+
BoUpSLP::vectorizeTree(MapVector<Value *, DebugLoc> &ExternallyUsedValues) {
28112810

28122811
// All blocks must be scheduled before any instructions are inserted.
28132812
for (auto &BSIter : BlocksSchedules) {
@@ -2869,6 +2868,7 @@ BoUpSLP::vectorizeTree(ExtraValueToDebugLocsMap &ExternallyUsedValues) {
28692868
assert(ExternallyUsedValues.count(Scalar) &&
28702869
"Scalar with nullptr as an external user must be registered in "
28712870
"ExternallyUsedValues map");
2871+
DebugLoc DL = ExternallyUsedValues[Scalar];
28722872
if (auto *VecI = dyn_cast<Instruction>(Vec)) {
28732873
Builder.SetInsertPoint(VecI->getParent(),
28742874
std::next(VecI->getIterator()));
@@ -2878,8 +2878,8 @@ BoUpSLP::vectorizeTree(ExtraValueToDebugLocsMap &ExternallyUsedValues) {
28782878
Value *Ex = Builder.CreateExtractElement(Vec, Lane);
28792879
Ex = extend(ScalarRoot, Ex, Scalar->getType());
28802880
CSEBlocks.insert(cast<Instruction>(Scalar)->getParent());
2881-
std::swap(ExternallyUsedValues[Ex], ExternallyUsedValues[Scalar]);
2882-
assert(ExternallyUsedValues[Scalar].empty());
2881+
ExternallyUsedValues.erase(Scalar);
2882+
ExternallyUsedValues[Ex] = DL;
28832883
continue;
28842884
}
28852885

@@ -4439,11 +4439,9 @@ class HorizontalReduction {
44394439
Builder.setFastMathFlags(Unsafe);
44404440
unsigned i = 0;
44414441

4442-
BoUpSLP::ExtraValueToDebugLocsMap ExternallyUsedValues;
4443-
// The same extra argument may be used several time, so log each attempt
4444-
// to use it.
4442+
MapVector<Value *, DebugLoc> ExternallyUsedValues;
44454443
for (auto &Pair : ExtraArgs)
4446-
ExternallyUsedValues[Pair.second].push_back(Pair.first->getDebugLoc());
4444+
ExternallyUsedValues[Pair.second] = Pair.first->getDebugLoc();
44474445
while (i < NumReducedVals - ReduxWidth + 1 && ReduxWidth > 2) {
44484446
auto VL = makeArrayRef(&ReducedVals[i], ReduxWidth);
44494447
V.buildTree(VL, ExternallyUsedValues, ReductionOps);
@@ -4491,14 +4489,9 @@ class HorizontalReduction {
44914489
Builder.CreateBinOp(ReductionOpcode, VectorizedTree, I);
44924490
}
44934491
for (auto &Pair : ExternallyUsedValues) {
4494-
if (Pair.second.empty())
4495-
continue;
4496-
// Add each externally used value to the final reduction.
4497-
for (auto &DL : Pair.second) {
4498-
Builder.SetCurrentDebugLocation(DL);
4499-
VectorizedTree = Builder.CreateBinOp(ReductionOpcode, VectorizedTree,
4500-
Pair.first, "bin.extra");
4501-
}
4492+
Builder.SetCurrentDebugLocation(Pair.second);
4493+
VectorizedTree = Builder.CreateBinOp(ReductionOpcode, VectorizedTree,
4494+
Pair.first, "bin.extra");
45024495
}
45034496
// Update users.
45044497
if (ReductionPHI && !isa<UndefValue>(ReductionPHI)) {

test/Transforms/SLPVectorizer/X86/horizontal-list.ll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,10 +1473,9 @@ define float @extra_args_same_several_times(float* nocapture readonly %x, i32 %a
14731473
; CHECK-NEXT: [[TMP2:%.*]] = extractelement <8 x float> [[BIN_RDX4]], i32 0
14741474
; CHECK-NEXT: [[BIN_EXTRA:%.*]] = fadd fast float [[TMP2]], [[ADD]]
14751475
; CHECK-NEXT: [[BIN_EXTRA5:%.*]] = fadd fast float [[BIN_EXTRA]], 5.000000e+00
1476-
; CHECK-NEXT: [[BIN_EXTRA6:%.*]] = fadd fast float [[BIN_EXTRA5]], 5.000000e+00
1477-
; CHECK-NEXT: [[BIN_EXTRA7:%.*]] = fadd fast float [[BIN_EXTRA6]], [[CONV]]
1476+
; CHECK-NEXT: [[BIN_EXTRA6:%.*]] = fadd fast float [[BIN_EXTRA5]], [[CONV]]
14781477
; CHECK-NEXT: [[ADD4_6:%.*]] = fadd fast float undef, [[ADD4_5]]
1479-
; CHECK-NEXT: ret float [[BIN_EXTRA7]]
1478+
; CHECK-NEXT: ret float [[BIN_EXTRA6]]
14801479
;
14811480
; THRESHOLD-LABEL: @extra_args_same_several_times(
14821481
; THRESHOLD-NEXT: entry:
@@ -1511,10 +1510,9 @@ define float @extra_args_same_several_times(float* nocapture readonly %x, i32 %a
15111510
; THRESHOLD-NEXT: [[TMP2:%.*]] = extractelement <8 x float> [[BIN_RDX4]], i32 0
15121511
; THRESHOLD-NEXT: [[BIN_EXTRA:%.*]] = fadd fast float [[TMP2]], [[ADD]]
15131512
; THRESHOLD-NEXT: [[BIN_EXTRA5:%.*]] = fadd fast float [[BIN_EXTRA]], 5.000000e+00
1514-
; THRESHOLD-NEXT: [[BIN_EXTRA6:%.*]] = fadd fast float [[BIN_EXTRA5]], 5.000000e+00
1515-
; THRESHOLD-NEXT: [[BIN_EXTRA7:%.*]] = fadd fast float [[BIN_EXTRA6]], [[CONV]]
1513+
; THRESHOLD-NEXT: [[BIN_EXTRA6:%.*]] = fadd fast float [[BIN_EXTRA5]], [[CONV]]
15161514
; THRESHOLD-NEXT: [[ADD4_6:%.*]] = fadd fast float undef, [[ADD4_5]]
1517-
; THRESHOLD-NEXT: ret float [[BIN_EXTRA7]]
1515+
; THRESHOLD-NEXT: ret float [[BIN_EXTRA6]]
15181516
;
15191517
entry:
15201518
%mul = mul nsw i32 %b, %a

0 commit comments

Comments
 (0)