aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Vectorize/LoopVectorize.cpp
diff options
context:
space:
mode:
authorNadav Rotem <nrotem@apple.com>2013-01-05 01:15:47 +0000
committerNadav Rotem <nrotem@apple.com>2013-01-05 01:15:47 +0000
commitd5b92c389133c5d587e4094af553ec345ed40045 (patch)
tree9e365b772b10da4ddd31d3043157cf2a0332e9db /lib/Transforms/Vectorize/LoopVectorize.cpp
parentf7737b5baad59f5352d21ef77bb2e2a767e9ed0f (diff)
iLoopVectorize: Non commutative operators can be used as reduction variables as long as the reduction chain is used in the LHS.
PR14803. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171583 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Vectorize/LoopVectorize.cpp')
-rw-r--r--lib/Transforms/Vectorize/LoopVectorize.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp
index 5e2d7971f8..af2e8464d0 100644
--- a/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -1912,10 +1912,6 @@ bool LoopVectorizationLegality::AddReductionVar(PHINode *Phi,
if (Iter->use_empty())
return false;
- // Any reduction instr must be of one of the allowed kinds.
- if (!isReductionInstr(Iter, Kind))
- return false;
-
// Did we find a user inside this loop already ?
bool FoundInBlockUser = false;
// Did we reach the initial PHI node already ?
@@ -1953,6 +1949,16 @@ bool LoopVectorizationLegality::AddReductionVar(PHINode *Phi,
if (FoundInBlockUser)
return false;
FoundInBlockUser = true;
+
+ // Any reduction instr must be of one of the allowed kinds.
+ if (!isReductionInstr(U, Kind))
+ return false;
+
+ // Reductions of instructions such as Div, and Sub is only
+ // possible if the LHS is the reduction variable.
+ if (!U->isCommutative() && U->getOperand(0) != Iter)
+ return false;
+
Iter = U;
}
@@ -1985,8 +1991,11 @@ LoopVectorizationLegality::isReductionInstr(Instruction *I,
case Instruction::PHI:
// possibly.
return true;
+ case Instruction::Sub:
case Instruction::Add:
return Kind == IntegerAdd;
+ case Instruction::SDiv:
+ case Instruction::UDiv:
case Instruction::Mul:
return Kind == IntegerMult;
case Instruction::And: