[llvm] e7f48d7 - [NFC][IRCE] Extract 'IV vs Limit' parsing to a separate method

Aleksandr Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 4 06:19:23 PDT 2023


Author: Aleksandr Popov
Date: 2023-07-03T10:19:21+02:00
New Revision: e7f48d735de45250bd9fbca34c5b7b5609f6da2d

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

LOG: [NFC][IRCE] Extract 'IV vs Limit' parsing to a separate method

Next step of the preparatory refactoring for the upcoming support of new
new range check form to parse.

This change isolates logic of 'IV vs Limit' range check parsing to
simplify adding parsers for new range checks forms.

Reviewed By: skatkov
Differential Revision: https://reviews.llvm.org/D154160

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
index c3955382d92c35..fdf465496e394b 100644
--- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -150,6 +150,11 @@ class InductiveRangeCheck {
                              SmallVectorImpl<InductiveRangeCheck> &Checks,
                              SmallPtrSetImpl<Value *> &Visited);
 
+  static bool parseIvAgaisntLimit(Loop *L, Value *LHS, Value *RHS,
+                                  ICmpInst::Predicate Pred, ScalarEvolution &SE,
+                                  const SCEVAddRecExpr *&Index,
+                                  const SCEV *&End);
+
 public:
   const SCEV *getBegin() const { return Begin; }
   const SCEV *getStep() const { return Step; }
@@ -261,11 +266,6 @@ bool InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
     return SE.isLoopInvariant(SE.getSCEV(V), L);
   };
 
-  auto SIntMaxSCEV = [&](Type *T) {
-    unsigned BitWidth = cast<IntegerType>(T)->getBitWidth();
-    return SE.getConstant(APInt::getSignedMaxValue(BitWidth));
-  };
-
   ICmpInst::Predicate Pred = ICI->getPredicate();
   Value *LHS = ICI->getOperand(0);
   Value *RHS = ICI->getOperand(1);
@@ -278,6 +278,24 @@ bool InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
     // Both LHS and RHS are loop variant
     return false;
 
+  if (parseIvAgaisntLimit(L, LHS, RHS, Pred, SE, Index, End))
+    return true;
+
+  return false;
+}
+
+// Try to parse range check in the form of "IV vs Limit"
+bool InductiveRangeCheck::parseIvAgaisntLimit(Loop *L, Value *LHS, Value *RHS,
+                                              ICmpInst::Predicate Pred,
+                                              ScalarEvolution &SE,
+                                              const SCEVAddRecExpr *&Index,
+                                              const SCEV *&End) {
+
+  auto SIntMaxSCEV = [&](Type *T) {
+    unsigned BitWidth = cast<IntegerType>(T)->getBitWidth();
+    return SE.getConstant(APInt::getSignedMaxValue(BitWidth));
+  };
+
   const auto *AddRec = dyn_cast<SCEVAddRecExpr>(SE.getSCEV(LHS));
   if (!AddRec)
     return false;


        


More information about the llvm-commits mailing list