[llvm] 63dd173 - [NFC] Collect ext users into vector instead of finding them twice

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 16 23:02:04 PST 2020


Author: Max Kazantsev
Date: 2020-11-17T14:01:43+07:00
New Revision: 63dd1734b2ed427170e1423285cc2767f6272b04

URL: https://github.com/llvm/llvm-project/commit/63dd1734b2ed427170e1423285cc2767f6272b04
DIFF: https://github.com/llvm/llvm-project/commit/63dd1734b2ed427170e1423285cc2767f6272b04.diff

LOG: [NFC] Collect ext users into vector instead of finding them twice

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 f5c92a5f60cf..52f3a08fda27 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -1568,6 +1568,7 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) {
 
   // 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;
@@ -1578,6 +1579,7 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) {
       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");
@@ -1600,15 +1602,7 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) {
   WideBO->copyIRFlags(NarrowBO);
   ExtendKindMap[NarrowUse] = ExtKind;
 
-  for (Use &U : NarrowUse->uses()) {
-    // Ignore narrow def: it will be removed after the transform.
-    if (U.getUser() == NarrowDef)
-      continue;
-    Instruction *User = nullptr;
-    if (ExtKind == SignExtended)
-      User = cast<SExtInst>(U.getUser());
-    else
-      User = cast<ZExtInst>(U.getUser());
+  for (Instruction *User : ExtUsers) {
     assert(User->getType() == WideType && "Checked before!");
     LLVM_DEBUG(dbgs() << "INDVARS: eliminating " << *User << " replaced by "
                       << *WideBO << "\n");


        


More information about the llvm-commits mailing list