[llvm] d02a40b - [IndVars][NFC] Separate creation of condition and replacement in foldExit

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 03:00:15 PST 2022


Author: Max Kazantsev
Date: 2022-12-12T17:59:45+07:00
New Revision: d02a40b559320e8d37ec2c80a6575ce138c3c55b

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

LOG: [IndVars][NFC] Separate creation of condition and replacement in foldExit

It is a preparatory step for further improvements.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index 9d666f76cb0c..55a22ae1d642 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<WeakTrackingVH> &DeadInsts) {
+static Constant *createFoldedExitCond(const Loop *L, 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);
+  return ConstantInt::get(OldCond->getType(),
+                          IsTaken ? ExitIfTrue : !ExitIfTrue);
+}
+
+static void foldExit(const Loop *L, BasicBlock *ExitingBB, bool IsTaken,
+                     SmallVectorImpl<WeakTrackingVH> &DeadInsts) {
+  BranchInst *BI = cast<BranchInst>(ExitingBB->getTerminator());
+  auto *NewCond = createFoldedExitCond(L, ExitingBB, IsTaken);
   replaceExitCond(BI, NewCond, DeadInsts);
 }
 


        


More information about the llvm-commits mailing list