diff options
author | Max Kazantsev <mkazantsev@azul.com> | 2021-03-19 12:00:06 +0700 |
---|---|---|
committer | Max Kazantsev <mkazantsev@azul.com> | 2021-03-19 12:28:22 +0700 |
commit | 16370e02a715717dd585537f02eb3e3a3221637e (patch) | |
tree | 7c5accf55a698b3af64ff27ac5a823ba26488cd1 /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | |
parent | fc1812a0ad757838b66aab57e1df720ec205a16a (diff) | |
download | llvm-16370e02a715717dd585537f02eb3e3a3221637e.zip llvm-16370e02a715717dd585537f02eb3e3a3221637e.tar.gz llvm-16370e02a715717dd585537f02eb3e3a3221637e.tar.bz2 |
[IndVars] Provide eliminateIVComparison with context
We can prove more predicates when we have a context when eliminating ICmp.
As first (and very obvious) approximation we can use the ICmp instruction itself,
though in the future we are going to use a common dominator of all its users.
Need some refactoring before that.
Observed ~0.5% negative compile time impact.
Differential Revision: https://reviews.llvm.org/D98697
Reviewed By: lebedev.ri
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index d0c43bb..120556f 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -261,9 +261,10 @@ void SimplifyIndvar::eliminateIVComparison(ICmpInst *ICmp, Value *IVOperand) { const SCEV *S = SE->getSCEVAtScope(ICmp->getOperand(IVOperIdx), ICmpLoop); const SCEV *X = SE->getSCEVAtScope(ICmp->getOperand(1 - IVOperIdx), ICmpLoop); - // If the condition is always true or always false, replace it with - // a constant value. - if (auto Ev = SE->evaluatePredicate(Pred, S, X)) { + // If the condition is always true or always false in the given context, + // replace it with a constant value. + // TODO: We can sharpen the context to common dominator of all ICmp's users. + if (auto Ev = SE->evaluatePredicateAt(Pred, S, X, ICmp)) { ICmp->replaceAllUsesWith(ConstantInt::getBool(ICmp->getContext(), *Ev)); DeadInsts.emplace_back(ICmp); LLVM_DEBUG(dbgs() << "INDVARS: Eliminated comparison: " << *ICmp << '\n'); |