[NFC] Split lambda into 2 parts for further reuse
authorMax Kazantsev <mkazantsev@azul.com>
Tue, 3 Nov 2020 07:13:28 +0000 (14:13 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Tue, 3 Nov 2020 07:13:55 +0000 (14:13 +0700)
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

index 0ee0d6e..650e049 100644 (file)
@@ -2406,15 +2406,20 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) {
   }
 #endif
 
+  auto ReplaceExitCond = [&](BranchInst *BI, Value *NewCond) {
+    auto *OldCond = BI->getCondition();
+    BI->setCondition(NewCond);
+    if (OldCond->use_empty())
+      DeadInsts.emplace_back(OldCond);
+  };
+
   auto FoldExit = [&](BasicBlock *ExitingBB, bool IsTaken) {
     BranchInst *BI = cast<BranchInst>(ExitingBB->getTerminator());
     bool ExitIfTrue = !L->contains(*succ_begin(ExitingBB));
     auto *OldCond = BI->getCondition();
     auto *NewCond = ConstantInt::get(OldCond->getType(),
                                      IsTaken ? ExitIfTrue : !ExitIfTrue);
-    BI->setCondition(NewCond);
-    if (OldCond->use_empty())
-      DeadInsts.emplace_back(OldCond);
+    ReplaceExitCond(BI, NewCond);
   };
 
   bool Changed = false;