diff options
author | Max Kazantsev <max.kazantsev@azul.com> | 2018-03-27 04:54:00 +0000 |
---|---|---|
committer | Max Kazantsev <max.kazantsev@azul.com> | 2018-03-27 04:54:00 +0000 |
commit | a63d333881e20f3df462263ad6bc557ae3c3e024 (patch) | |
tree | e98775e94960286740a8387f2c6b02abb120112b /llvm/lib/Analysis | |
parent | 44a23f42837a680b00f88389a4695845016da6ac (diff) | |
download | bcm5719-llvm-a63d333881e20f3df462263ad6bc557ae3c3e024.tar.gz bcm5719-llvm-a63d333881e20f3df462263ad6bc557ae3c3e024.zip |
[SCEV] Add one more case in computeConstantDifference
This patch teaches `computeConstantDifference` handle calculation of constant
difference between `(X + C1)` and `(X + C2)` which is `(C2 - C1)`.
Differential Revision: https://reviews.llvm.org/D43759
Reviewed By: anna
llvm-svn: 328609
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 004eac7f555..b44107d9a89 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -9449,17 +9449,25 @@ Optional<APInt> ScalarEvolution::computeConstantDifference(const SCEV *More, return M - L; } - const SCEV *L, *R; SCEV::NoWrapFlags Flags; - if (splitBinaryAdd(Less, L, R, Flags)) - if (const auto *LC = dyn_cast<SCEVConstant>(L)) - if (R == More) - return -(LC->getAPInt()); - - if (splitBinaryAdd(More, L, R, Flags)) - if (const auto *LC = dyn_cast<SCEVConstant>(L)) - if (R == Less) - return LC->getAPInt(); + const SCEV *LLess = nullptr, *RLess = nullptr; + const SCEV *LMore = nullptr, *RMore = nullptr; + const SCEVConstant *C1 = nullptr, *C2 = nullptr; + // Compare (X + C1) vs X. + if (splitBinaryAdd(Less, LLess, RLess, Flags)) + if ((C1 = dyn_cast<SCEVConstant>(LLess))) + if (RLess == More) + return -(C1->getAPInt()); + + // Compare X vs (X + C2). + if (splitBinaryAdd(More, LMore, RMore, Flags)) + if ((C2 = dyn_cast<SCEVConstant>(LMore))) + if (RMore == Less) + return C2->getAPInt(); + + // Compare (X + C1) vs (X + C2). + if (C1 && C2 && RLess == RMore) + return C2->getAPInt() - C1->getAPInt(); return None; } |