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

Aleksandr Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 29 15:07:57 PDT 2023


aleksandr.popov created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
aleksandr.popov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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

Previous one: https://reviews.llvm.org/D154158

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


https://reviews.llvm.org/D154160

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


Index: llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -151,6 +151,11 @@
                              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 @@
     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 @@
     // 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154160.536022.patch
Type: text/x-patch
Size: 2072 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230629/2ba8d3e9/attachment.bin>


More information about the llvm-commits mailing list