From 4b5e848befdf786f5c905adf3b6c589216a24bff Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Mon, 26 Oct 2020 14:49:37 +0700 Subject: [PATCH] [NFC] Factor out common code into lambda for further improvement --- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 30f8f11..b5275cf 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -2416,14 +2416,16 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) { // Okay, we do not know the exit count here. Can we at least prove that it // will remain the same within iteration space? auto *BI = cast(ExitingBB->getTerminator()); - if (isTrivialCond(L, BI, SE, false)) { - FoldExit(ExitingBB, false); - Changed = true; - } - if (isTrivialCond(L, BI, SE, true)) { - FoldExit(ExitingBB, true); + auto OptimizeCond = [&](bool Inverted, const SCEV *MaxIter) { + if (isTrivialCond(L, BI, SE, Inverted)) { + FoldExit(ExitingBB, Inverted); + return true; + } + return false; + }; + if (OptimizeCond(false, MaxExitCount) || + OptimizeCond(true, MaxExitCount)) Changed = true; - } continue; } -- 2.7.4