aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar
diff options
context:
space:
mode:
authorMax Kazantsev <mkazantsev@azul.com>2020-11-18 17:56:34 +0700
committerMax Kazantsev <mkazantsev@azul.com>2020-11-18 18:20:05 +0700
commitf33118c61ce051f13515f5c9b862302fc4fdb89e (patch)
tree242e626c31680c354a41fb915786b23e593cdaa6 /llvm/lib/Transforms/Scalar
parent1e6fc2fa532c280abec04f83410dfdb3760dfc0f (diff)
downloadllvm-project-f33118c61ce051f13515f5c9b862302fc4fdb89e.tar.gz
[IndVars] Support different types of ExitCount when optimizing exit conds
In some cases we can handle IV and iter count of different types. It's a typical situation after IV have been widened. This patch adds support for such cases, when legal. Differential Revision: https://reviews.llvm.org/D88528 Reviewed By: skatkov
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
-rw-r--r--llvm/lib/Transforms/Scalar/IndVarSimplify.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index e36d2e7f3a5b..d9a959d2fb6d 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -1360,6 +1360,18 @@ static bool optimizeLoopExitWithUnknownExitCount(
if (Inverted)
return false;
+ auto *ARTy = LHSS->getType();
+ auto *MaxIterTy = MaxIter->getType();
+ // If possible, adjust types.
+ if (SE->getTypeSizeInBits(ARTy) > SE->getTypeSizeInBits(MaxIterTy))
+ MaxIter = SE->getZeroExtendExpr(MaxIter, ARTy);
+ else if (SE->getTypeSizeInBits(ARTy) < SE->getTypeSizeInBits(MaxIterTy)) {
+ const SCEV *MinusOne = SE->getMinusOne(ARTy);
+ auto *MaxAllowedIter = SE->getZeroExtendExpr(MinusOne, MaxIterTy);
+ if (SE->isKnownPredicateAt(ICmpInst::ICMP_ULE, MaxIter, MaxAllowedIter, BI))
+ MaxIter = SE->getTruncateExpr(MaxIter, ARTy);
+ }
+
if (SkipLastIter) {
const SCEV *One = SE->getOne(MaxIter->getType());
MaxIter = SE->getMinusSCEV(MaxIter, One);