aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
diff options
context:
space:
mode:
authorMax Kazantsev <mkazantsev@azul.com>2021-03-22 11:07:32 +0700
committerMax Kazantsev <mkazantsev@azul.com>2021-03-22 11:55:57 +0700
commit8fab9f824fcaa38edebbd0f6b86f8612a4212cdd (patch)
tree0ecb65735727ba85f1ed5b5c83098b2629930abe /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
parentfc36a511c66702e1bbbfeac701423f18ad4e137e (diff)
downloadllvm-8fab9f824fcaa38edebbd0f6b86f8612a4212cdd.zip
llvm-8fab9f824fcaa38edebbd0f6b86f8612a4212cdd.tar.gz
llvm-8fab9f824fcaa38edebbd0f6b86f8612a4212cdd.tar.bz2
[IndVars] Sharpen context in eliminateIVComparison
When eliminating comparisons, we can use common dominator of all its users as context. This gives better results when ICMP is not computed right before the branch that uses it. Differential Revision: https://reviews.llvm.org/D98924 Reviewed By: lebedev.ri
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyIndVar.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index f0e4466..d4f325c 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -281,8 +281,11 @@ void SimplifyIndvar::eliminateIVComparison(ICmpInst *ICmp, Value *IVOperand) {
// 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)) {
+ SmallVector<Instruction *, 4> Users;
+ for (auto *U : ICmp->users())
+ Users.push_back(cast<Instruction>(U));
+ const Instruction *CtxI = findCommonDominator(Users, *DT);
+ if (auto Ev = SE->evaluatePredicateAt(Pred, S, X, CtxI)) {
ICmp->replaceAllUsesWith(ConstantInt::getBool(ICmp->getContext(), *Ev));
DeadInsts.emplace_back(ICmp);
LLVM_DEBUG(dbgs() << "INDVARS: Eliminated comparison: " << *ICmp << '\n');