diff options
author | Max Kazantsev <mkazantsev@azul.com> | 2020-11-25 11:46:22 +0700 |
---|---|---|
committer | Max Kazantsev <mkazantsev@azul.com> | 2020-11-25 11:47:39 +0700 |
commit | 28d7ba15435f055562d18ee7111db4adbaf28fae (patch) | |
tree | 4f1cb21fab699480f289983b8b2a0101faaf4b0a /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | |
parent | 8e6d92026c624386b85675a4664e2666225fcfac (diff) | |
download | llvm-28d7ba15435f055562d18ee7111db4adbaf28fae.zip llvm-28d7ba15435f055562d18ee7111db4adbaf28fae.tar.gz llvm-28d7ba15435f055562d18ee7111db4adbaf28fae.tar.bz2 |
[IndVars] Use more precise context when eliminating narrowing
When deciding to widen narrow use, we may need to prove some facts
about it. For proof, the context is used. Currently we take the instruction
being widened as the context.
However, we may be more precise here if we take as context the point that
dominates all users of instruction being widened.
Differential Revision: https://reviews.llvm.org/D90456
Reviewed By: skatkov
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index 2693f45..290f367 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -1561,6 +1561,21 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) { return true; } + // We'll prove some facts that should be true in the context of ext users. If + // there is no users, we are done now. If there are some, pick their common + // dominator as context. + Instruction *Context = nullptr; + for (auto *Ext : ExtUsers) { + if (!Context || DT->dominates(Ext, Context)) + Context = Ext; + else if (!DT->dominates(Context, Ext)) + // For users that don't have dominance relation, use common dominator. + Context = + DT->findNearestCommonDominator(Context->getParent(), Ext->getParent()) + ->getTerminator(); + } + assert(Context && "Context not found?"); + if (!CanSignExtend && !CanZeroExtend) { // Because InstCombine turns 'sub nuw' to 'add' losing the no-wrap flag, we // will most likely not see it. Let's try to prove it. @@ -1573,7 +1588,7 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) { if (!SE->isKnownNegative(RHS)) return false; bool ProvedSubNUW = SE->isKnownPredicateAt( - ICmpInst::ICMP_UGE, LHS, SE->getNegativeSCEV(RHS), NarrowUse); + ICmpInst::ICMP_UGE, LHS, SE->getNegativeSCEV(RHS), Context); if (!ProvedSubNUW) return false; // In fact, our 'add' is 'sub nuw'. We will need to widen the 2nd operand as |