From: Sanjoy Das Date: Fri, 14 Apr 2017 15:50:07 +0000 (+0000) Subject: Simplify PostIncTransform further; NFC X-Git-Tag: android-x86-7.1-r4~17689 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=7fd520400d42612e8d394f02410717358e273366;p=android-x86%2Fexternal-llvm.git Simplify PostIncTransform further; NFC Instead of having two ways to check if an add recurrence needs to be normalized, just pass in one predicate to decide that. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300333 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/ScalarEvolutionNormalization.cpp b/lib/Analysis/ScalarEvolutionNormalization.cpp index 89237273d01..21d1c182713 100644 --- a/lib/Analysis/ScalarEvolutionNormalization.cpp +++ b/lib/Analysis/ScalarEvolutionNormalization.cpp @@ -33,16 +33,15 @@ enum TransformKind { /// map of transformed expressions. class PostIncTransform { TransformKind Kind; - Optional Pred; - const PostIncLoopSet &Loops; + NormalizePredTy Pred; ScalarEvolution &SE; DenseMap Transformed; public: - PostIncTransform(TransformKind kind, Optional Pred, - const PostIncLoopSet &loops, ScalarEvolution &se) - : Kind(kind), Pred(Pred), Loops(loops), SE(se) {} + PostIncTransform(TransformKind kind, NormalizePredTy Pred, + ScalarEvolution &se) + : Kind(kind), Pred(Pred), SE(se) {} const SCEV *TransformSubExpr(const SCEV *S); @@ -70,13 +69,13 @@ const SCEV *PostIncTransform::TransformImpl(const SCEV *S) { if (const SCEVAddRecExpr *AR = dyn_cast(S)) { // An addrec. This is the interesting part. SmallVector Operands; - const Loop *L = AR->getLoop(); transform(AR->operands(), std::back_inserter(Operands), [&](const SCEV *Op) { return TransformSubExpr(Op); }); // Conservatively use AnyWrap until/unless we need FlagNW. - const SCEV *Result = SE.getAddRecExpr(Operands, L, SCEV::FlagAnyWrap); + const SCEV *Result = + SE.getAddRecExpr(Operands, AR->getLoop(), SCEV::FlagAnyWrap); switch (Kind) { case Normalize: // We want to normalize step expression, because otherwise we might not be @@ -93,7 +92,7 @@ const SCEV *PostIncTransform::TransformImpl(const SCEV *S) { // (100 /u {1,+,1}<%bb16>)}<%bb25> // Note that the initial value changes after normalization + // denormalization, which isn't correct. - if ((Pred && (*Pred)(AR)) || (!Pred && Loops.count(L))) { + if (Pred(AR)) { const SCEV *TransformedStep = TransformSubExpr(AR->getStepRecurrence(SE)); Result = SE.getMinusSCEV(Result, TransformedStep); @@ -107,7 +106,7 @@ const SCEV *PostIncTransform::TransformImpl(const SCEV *S) { case Denormalize: // Here we want to normalize step expressions for the same reasons, as // stated above. - if (Loops.count(L)) { + if (Pred(AR)) { const SCEV *TransformedStep = TransformSubExpr(AR->getStepRecurrence(SE)); Result = SE.getAddExpr(Result, TransformedStep); @@ -171,27 +170,31 @@ const SCEV *PostIncTransform::TransformSubExpr(const SCEV *S) { /// Top level driver for transforming an expression DAG into its requested /// post-inc form (either "Normalized" or "Denormalized"). static const SCEV *TransformForPostIncUse(TransformKind Kind, const SCEV *S, - Optional Pred, - const PostIncLoopSet &Loops, + NormalizePredTy Pred, ScalarEvolution &SE) { - PostIncTransform Transform(Kind, Pred, Loops, SE); + PostIncTransform Transform(Kind, Pred, SE); return Transform.TransformSubExpr(S); } const SCEV *llvm::normalizeForPostIncUse(const SCEV *S, const PostIncLoopSet &Loops, ScalarEvolution &SE) { - return TransformForPostIncUse(Normalize, S, None, Loops, SE); + auto Pred = [&](const SCEVAddRecExpr *AR) { + return Loops.count(AR->getLoop()); + }; + return TransformForPostIncUse(Normalize, S, Pred, SE); } const SCEV *llvm::normalizeForPostIncUseIf(const SCEV *S, NormalizePredTy Pred, ScalarEvolution &SE) { - PostIncLoopSet Empty; - return TransformForPostIncUse(Normalize, S, Pred, Empty, SE); + return TransformForPostIncUse(Normalize, S, Pred, SE); } const SCEV *llvm::denormalizeForPostIncUse(const SCEV *S, const PostIncLoopSet &Loops, ScalarEvolution &SE) { - return TransformForPostIncUse(Denormalize, S, None, Loops, SE); + auto Pred = [&](const SCEVAddRecExpr *AR) { + return Loops.count(AR->getLoop()); + }; + return TransformForPostIncUse(Denormalize, S, Pred, SE); }