diff options
author | Arnold Schwaighofer <aschwaighofer@apple.com> | 2013-05-05 01:54:42 +0000 |
---|---|---|
committer | Arnold Schwaighofer <aschwaighofer@apple.com> | 2013-05-05 01:54:42 +0000 |
commit | c1738fdadd1c969f13bbf09fe9c36fff56ccd709 (patch) | |
tree | e97326bd2650fbd99f7751a113e1888449fc852f /lib/Transforms | |
parent | 5c332dbd30d9398ed25b30c3080506f7b8e92290 (diff) |
LoopVectorize: We don't need an identity element for min/max reductions
We can just use the initial element that feeds the reduction.
max(max(x, y), z) == max(max(x,y), max(x,z))
radar://13723044
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181141 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Vectorize/LoopVectorize.cpp | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index 2250712a8e..1c7397bfa6 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -498,8 +498,7 @@ public: /// This function returns the identity element (or neutral element) for /// the operation K. - static Constant *getReductionIdentity(ReductionKind K, Type *Tp, - MinMaxReductionKind MinMaxK); + static Constant *getReductionIdentity(ReductionKind K, Type *Tp); private: /// Check if a single basic block loop is vectorizable. /// At this point we know that this is a loop with a constant trip count @@ -1501,8 +1500,7 @@ InnerLoopVectorizer::createEmptyLoop(LoopVectorizationLegality *Legal) { /// This function returns the identity element (or neutral element) for /// the operation K. Constant* -LoopVectorizationLegality::getReductionIdentity(ReductionKind K, Type *Tp, - MinMaxReductionKind MinMaxK) { +LoopVectorizationLegality::getReductionIdentity(ReductionKind K, Type *Tp) { switch (K) { case RK_IntegerXor: case RK_IntegerAdd: @@ -1521,24 +1519,6 @@ LoopVectorizationLegality::getReductionIdentity(ReductionKind K, Type *Tp, case RK_FloatAdd: // Adding zero to a number does not change it. return ConstantFP::get(Tp, 0.0L); - case RK_IntegerMinMax: - switch(MinMaxK) { - default: llvm_unreachable("Unknown min/max predicate"); - case MRK_UIntMin: - return ConstantInt::getAllOnesValue(Tp); - case MRK_UIntMax: - return ConstantInt::get(Tp, 0); - case MRK_SIntMin: { - unsigned BitWidth = Tp->getPrimitiveSizeInBits(); - return ConstantInt::get(Tp->getContext(), - APInt::getSignedMaxValue(BitWidth)); - } - case LoopVectorizationLegality::MRK_SIntMax: { - unsigned BitWidth = Tp->getPrimitiveSizeInBits(); - return ConstantInt::get(Tp->getContext(), - APInt::getSignedMinValue(BitWidth)); - } - } default: llvm_unreachable("Unknown reduction kind"); } @@ -1761,16 +1741,23 @@ InnerLoopVectorizer::vectorizeLoop(LoopVectorizationLegality *Legal) { // Find the reduction identity variable. Zero for addition, or, xor, // one for multiplication, -1 for And. - Constant *Iden = - LoopVectorizationLegality::getReductionIdentity(RdxDesc.Kind, - VecTy->getScalarType(), - RdxDesc.MinMaxKind); - Constant *Identity = ConstantVector::getSplat(VF, Iden); - - // This vector is the Identity vector where the first element is the - // incoming scalar reduction. - Value *VectorStart = Builder.CreateInsertElement(Identity, - RdxDesc.StartValue, Zero); + Value *Identity; + Value *VectorStart; + if (RdxDesc.Kind == LoopVectorizationLegality::RK_IntegerMinMax) + // MinMax reduction have the start value as their identify. + VectorStart = Identity = Builder.CreateVectorSplat(VF, RdxDesc.StartValue, + "minmax.ident"); + else { + Constant *Iden = + LoopVectorizationLegality::getReductionIdentity(RdxDesc.Kind, + VecTy->getScalarType()); + Identity = ConstantVector::getSplat(VF, Iden); + + // This vector is the Identity vector where the first element is the + // incoming scalar reduction. + VectorStart = Builder.CreateInsertElement(Identity, + RdxDesc.StartValue, Zero); + } // Fix the vector-loop phi. // We created the induction variable so we know that the |