diff options
author | Michael Zolotukhin <mzolotukhin@apple.com> | 2014-03-18 17:34:03 +0000 |
---|---|---|
committer | Michael Zolotukhin <mzolotukhin@apple.com> | 2014-03-18 17:34:03 +0000 |
commit | ed0a7761e5f249aad4c9d0e85f268c1b5df798ca (patch) | |
tree | 723933f98422938b2d0c1773a3fe07620726b799 /llvm/lib/Analysis/ScalarEvolutionNormalization.cpp | |
parent | 28f46d9f390123b822f82403649284d6f61e6153 (diff) | |
download | llvm-ed0a7761e5f249aad4c9d0e85f268c1b5df798ca.zip llvm-ed0a7761e5f249aad4c9d0e85f268c1b5df798ca.tar.gz llvm-ed0a7761e5f249aad4c9d0e85f268c1b5df798ca.tar.bz2 |
Add stride normalization to SCEV Normalize/Denormalize transformation.
llvm-svn: 204161
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolutionNormalization.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionNormalization.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp b/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp index 3303676..1e4c0bd 100644 --- a/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp @@ -131,7 +131,10 @@ TransformImpl(const SCEV *S, Instruction *User, Value *OperandValToReplace) { // expression: {-2,+,1,+,2} + {1,+,2} => {-1,+,3,+,2} if (AR->isAffine() && IVUseShouldUsePostIncValue(User, OperandValToReplace, L, &DT)) { - Result = SE.getMinusSCEV(Result, AR->getStepRecurrence(SE)); + const SCEV *TransformedStep = + TransformSubExpr(AR->getStepRecurrence(SE), + User, OperandValToReplace); + Result = SE.getMinusSCEV(Result, TransformedStep); Loops.insert(L); } #if 0 @@ -144,6 +147,20 @@ TransformImpl(const SCEV *S, Instruction *User, Value *OperandValToReplace) { #endif break; case Normalize: + // We want to normalize step expression, because otherwise we might not be + // able to denormalize to the original expression. + // + // Here is an example what will happen if we don't normalize step: + // ORIGINAL ISE: + // {(100 /u {1,+,1}<%bb16>),+,(100 /u {1,+,1}<%bb16>)}<%bb25> + // NORMALIZED ISE: + // {((-1 * (100 /u {1,+,1}<%bb16>)) + (100 /u {0,+,1}<%bb16>)),+, + // (100 /u {0,+,1}<%bb16>)}<%bb25> + // DENORMALIZED BACK ISE: + // {((2 * (100 /u {1,+,1}<%bb16>)) + (-1 * (100 /u {2,+,1}<%bb16>))),+, + // (100 /u {1,+,1}<%bb16>)}<%bb25> + // Note that the initial value changes after normalization + + // denormalization, which isn't correct. if (Loops.count(L)) { const SCEV *TransformedStep = TransformSubExpr(AR->getStepRecurrence(SE), @@ -157,8 +174,14 @@ TransformImpl(const SCEV *S, Instruction *User, Value *OperandValToReplace) { #endif break; case Denormalize: - if (Loops.count(L)) - Result = cast<SCEVAddRecExpr>(Result)->getPostIncExpr(SE); + // Here we want to normalize step expressions for the same reasons, as + // stated above. + if (Loops.count(L)) { + const SCEV *TransformedStep = + TransformSubExpr(AR->getStepRecurrence(SE), + User, OperandValToReplace); + Result = SE.getAddExpr(Result, TransformedStep); + } break; } return Result; |