From 0a0a77690bc142d880d15eb0b9b180b3ef8b17b9 Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Tue, 15 Jan 2019 11:16:14 +0000 Subject: [PATCH] [NFC] Remove some code duplication git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351185 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/InductiveRangeCheckElimination.cpp | 35 +++++-------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp index 6bd34176909..1c701bbee18 100644 --- a/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp +++ b/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp @@ -1260,29 +1260,20 @@ LoopConstrainer::RewrittenRangeInfo LoopConstrainer::changeIterationSpaceEnd( // EnterLoopCond - is it okay to start executing this `LS'? Value *EnterLoopCond = nullptr; - if (Increasing) - EnterLoopCond = IsSignedPredicate - ? B.CreateICmpSLT(LS.IndVarStart, ExitSubloopAt) - : B.CreateICmpULT(LS.IndVarStart, ExitSubloopAt); - else - EnterLoopCond = IsSignedPredicate - ? B.CreateICmpSGT(LS.IndVarStart, ExitSubloopAt) - : B.CreateICmpUGT(LS.IndVarStart, ExitSubloopAt); + auto Pred = + Increasing + ? (IsSignedPredicate ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT) + : (IsSignedPredicate ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT); + EnterLoopCond = B.CreateICmp(Pred, LS.IndVarStart, ExitSubloopAt); B.CreateCondBr(EnterLoopCond, LS.Header, RRI.PseudoExit); PreheaderJump->eraseFromParent(); LS.LatchBr->setSuccessor(LS.LatchBrExitIdx, RRI.ExitSelector); B.SetInsertPoint(LS.LatchBr); - Value *TakeBackedgeLoopCond = nullptr; - if (Increasing) - TakeBackedgeLoopCond = IsSignedPredicate - ? B.CreateICmpSLT(LS.IndVarBase, ExitSubloopAt) - : B.CreateICmpULT(LS.IndVarBase, ExitSubloopAt); - else - TakeBackedgeLoopCond = IsSignedPredicate - ? B.CreateICmpSGT(LS.IndVarBase, ExitSubloopAt) - : B.CreateICmpUGT(LS.IndVarBase, ExitSubloopAt); + Value *TakeBackedgeLoopCond = B.CreateICmp(Pred, LS.IndVarBase, + ExitSubloopAt); + Value *CondForBranch = LS.LatchBrExitIdx == 1 ? TakeBackedgeLoopCond : B.CreateNot(TakeBackedgeLoopCond); @@ -1294,15 +1285,7 @@ LoopConstrainer::RewrittenRangeInfo LoopConstrainer::changeIterationSpaceEnd( // IterationsLeft - are there any more iterations left, given the original // upper bound on the induction variable? If not, we branch to the "real" // exit. - Value *IterationsLeft = nullptr; - if (Increasing) - IterationsLeft = IsSignedPredicate - ? B.CreateICmpSLT(LS.IndVarBase, LS.LoopExitAt) - : B.CreateICmpULT(LS.IndVarBase, LS.LoopExitAt); - else - IterationsLeft = IsSignedPredicate - ? B.CreateICmpSGT(LS.IndVarBase, LS.LoopExitAt) - : B.CreateICmpUGT(LS.IndVarBase, LS.LoopExitAt); + Value *IterationsLeft = B.CreateICmp(Pred, LS.IndVarBase, LS.LoopExitAt); B.CreateCondBr(IterationsLeft, RRI.PseudoExit, LS.LatchExit); BranchInst *BranchToContinuation = -- 2.50.1