[llvm] 7c601d0 - [NFC] Move code earlier as preparation for further changes

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 19 01:27:43 PST 2020


Author: Max Kazantsev
Date: 2020-11-19T16:27:23+07:00
New Revision: 7c601d09a76b55d191448d70b47a0a575db914b6

URL: https://github.com/llvm/llvm-project/commit/7c601d09a76b55d191448d70b47a0a575db914b6
DIFF: https://github.com/llvm/llvm-project/commit/7c601d09a76b55d191448d70b47a0a575db914b6.diff

LOG: [NFC] Move code earlier as preparation for further changes

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyIndVar.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index 52f3a08fda27..0467f6debde5 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.


        


More information about the llvm-commits mailing list