From d02a40b559320e8d37ec2c80a6575ce138c3c55b Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Mon, 12 Dec 2022 17:48:42 +0700 Subject: [PATCH] [IndVars][NFC] Separate creation of condition and replacement in foldExit It is a preparatory step for further improvements. --- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 9d666f7..55a22ae 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -1298,13 +1298,19 @@ static void replaceExitCond(BranchInst *BI, Value *NewCond, DeadInsts.emplace_back(OldCond); } -static void foldExit(const Loop *L, BasicBlock *ExitingBB, bool IsTaken, - SmallVectorImpl &DeadInsts) { +static Constant *createFoldedExitCond(const Loop *L, BasicBlock *ExitingBB, + bool IsTaken) { BranchInst *BI = cast(ExitingBB->getTerminator()); bool ExitIfTrue = !L->contains(*succ_begin(ExitingBB)); auto *OldCond = BI->getCondition(); - auto *NewCond = - ConstantInt::get(OldCond->getType(), IsTaken ? ExitIfTrue : !ExitIfTrue); + return ConstantInt::get(OldCond->getType(), + IsTaken ? ExitIfTrue : !ExitIfTrue); +} + +static void foldExit(const Loop *L, BasicBlock *ExitingBB, bool IsTaken, + SmallVectorImpl &DeadInsts) { + BranchInst *BI = cast(ExitingBB->getTerminator()); + auto *NewCond = createFoldedExitCond(L, ExitingBB, IsTaken); replaceExitCond(BI, NewCond, DeadInsts); } -- 2.7.4