From 2e3d07d44776c5fff9eb6cfbeb3887785032b0a6 Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Thu, 19 Nov 2020 16:04:27 +0700 Subject: [PATCH] [NFC] Move code earlier as preparation for further changes --- lib/Transforms/Utils/SimplifyIndVar.cpp | 40 +++++++++++++++---------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/Transforms/Utils/SimplifyIndVar.cpp b/lib/Transforms/Utils/SimplifyIndVar.cpp index 52f3a08fda2..0467f6debde 100644 --- a/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/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 ExtUsers; + for (Use &U : NarrowUse->uses()) { + if (U.getUser() == NarrowDef) + continue; + Instruction *User = nullptr; + if (ExtKind == SignExtended) + User = dyn_cast(U.getUser()); + else + User = dyn_cast(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 ExtUsers; - for (Use &U : NarrowUse->uses()) { - if (U.getUser() == NarrowDef) - continue; - Instruction *User = nullptr; - if (ExtKind == SignExtended) - User = dyn_cast(U.getUser()); - else - User = dyn_cast(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.