[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
Tue Jul 4 06:19:31 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7f48d735de4: [NFC][IRCE] Extract 'IV vs Limit' parsing to a separate method (authored by aleksandr.popov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154160/new/

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
@@ -150,6 +150,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.537078.patch
Type: text/x-patch
Size: 2072 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230704/70215865/attachment.bin>


More information about the llvm-commits mailing list