LoopVectorizer: A reduction that has multiple uses of the reduction value is not

a reduction.

Really. Under certain circumstances (the use list of an instruction has to be
set up right - hence the extra pass in the test case) we would not recognize
when a value in a potential reduction cycle was used multiple times by the
reduction cycle.

Fixes PR18526.
radar://15851149

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199570 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Arnold Schwaighofer
2014-01-19 03:18:31 +00:00
parent e608d695de
commit 2becaaf3a1
2 changed files with 53 additions and 2 deletions

View File

@ -4535,13 +4535,22 @@ bool LoopVectorizationLegality::AddReductionVar(PHINode *Phi,
continue;
}
// Process instructions only once (termination).
// Process instructions only once (termination). Each reduction cycle
// value must only be used once, except by phi nodes and min/max
// reductions which are represented as a cmp followed by a select.
ReductionInstDesc IgnoredVal(false, 0);
if (VisitedInsts.insert(Usr)) {
if (isa<PHINode>(Usr))
PHIs.push_back(Usr);
else
NonPHIs.push_back(Usr);
}
} else if (!isa<PHINode>(Usr) &&
((!isa<FCmpInst>(Usr) &&
!isa<ICmpInst>(Usr) &&
!isa<SelectInst>(Usr)) ||
!isMinMaxSelectCmpPattern(Usr, IgnoredVal).IsReduction))
return false;
// Remember that we completed the cycle.
if (Usr == Phi)
FoundStartPHI = true;