diff options
author | Max Kazantsev <mkazantsev@azul.com> | 2020-11-19 16:04:27 +0700 |
---|---|---|
committer | Max Kazantsev <mkazantsev@azul.com> | 2020-11-19 16:27:23 +0700 |
commit | 7c601d09a76b55d191448d70b47a0a575db914b6 (patch) | |
tree | 481ff78b4996871aec765372f559ab3b88f73a3c /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | |
parent | 47518d6a0aed7ec3607aeacfa511dedda2cd67cb (diff) | |
download | llvm-7c601d09a76b55d191448d70b47a0a575db914b6.zip llvm-7c601d09a76b55d191448d70b47a0a575db914b6.tar.gz llvm-7c601d09a76b55d191448d70b47a0a575db914b6.tar.bz2 |
[NFC] Move code earlier as preparation for further changes
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index 52f3a08..0467f6d 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -1540,6 +1540,30 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) { bool CanSignExtend = ExtKind == SignExtended && OBO->hasNoSignedWrap(); bool CanZeroExtend = ExtKind == ZeroExtended && OBO->hasNoUnsignedWrap(); auto AnotherOpExtKind = ExtKind; + + // Check that all uses are either s/zext, or narrow def (in case of we are + // widening the IV increment). + SmallVector<Instruction *, 4> ExtUsers; + for (Use &U : NarrowUse->uses()) { + if (U.getUser() == NarrowDef) + continue; + Instruction *User = nullptr; + if (ExtKind == SignExtended) + User = dyn_cast<SExtInst>(U.getUser()); + else + User = dyn_cast<ZExtInst>(U.getUser()); + if (!User || User->getType() != WideType) + return false; + ExtUsers.push_back(User); + } + // 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. + if (ExtUsers.empty()) { + DeadInsts.emplace_back(NarrowUse); + return true; + } + 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. @@ -1566,22 +1590,6 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) { if (!AddRecOp1 || AddRecOp1->getLoop() != L) return false; - // Check that all uses are either s/zext, or narrow def (in case of we are - // widening the IV increment). - SmallVector<Instruction *, 4> ExtUsers; - for (Use &U : NarrowUse->uses()) { - if (U.getUser() == NarrowDef) - continue; - Instruction *User = nullptr; - if (ExtKind == SignExtended) - User = dyn_cast<SExtInst>(U.getUser()); - else - User = dyn_cast<ZExtInst>(U.getUser()); - if (!User || User->getType() != WideType) - return false; - ExtUsers.push_back(User); - } - LLVM_DEBUG(dbgs() << "Cloning arithmetic IVUser: " << *NarrowUse << "\n"); // Generating a widening use instruction. |