[PATCH] D43498: [SCEV] Extends the SCEVInitRewriter

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 19 22:21:11 PST 2018


skatkov created this revision.
skatkov added reviewers: sanjoy, mkazantsev, reames.

The patch introduces an additional parameter IgnoreOtherLoops to SCEVInitRewriter.
if it is equal to true then rewriter will not invalidate result in case
SCEV depends on other loops then specified during creation.

The patch does not change the default behavior.
This is a preparation for re-writing isKnownPredicate utility as
described in https://reviews.llvm.org/D42417.


https://reviews.llvm.org/D43498

Files:
  lib/Analysis/ScalarEvolution.cpp


Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -4086,11 +4086,16 @@
 
 namespace {
 
+/// Takes SCEV S and Loop L. For each AddRec sub-expression, use its start
+/// expression in case its Loop is L. If it is not L then
+/// if IgnoreOtherLoops is true then use AddRec itself
+/// otherwise rewrite cannot be done.
+/// If SCEV contains non-invariant unknown SCEV rewrite cannot be done.
 class SCEVInitRewriter : public SCEVRewriteVisitor<SCEVInitRewriter> {
 public:
-  static const SCEV *rewrite(const SCEV *S, const Loop *L,
-                             ScalarEvolution &SE) {
-    SCEVInitRewriter Rewriter(L, SE);
+  static const SCEV *rewrite(const SCEV *S, const Loop *L, ScalarEvolution &SE,
+                             bool IgnoreOtherLoops = false) {
+    SCEVInitRewriter Rewriter(L, SE, IgnoreOtherLoops);
     const SCEV *Result = Rewriter.visit(S);
     return Rewriter.isValid() ? Result : SE.getCouldNotCompute();
   }
@@ -4105,17 +4110,20 @@
     // Only allow AddRecExprs for this loop.
     if (Expr->getLoop() == L)
       return Expr->getStart();
-    Valid = false;
+    // If we should not ignore other loops then invalidate result.
+    Valid = Valid && IgnoreOtherLoops;
     return Expr;
   }
 
   bool isValid() { return Valid; }
 
 private:
-  explicit SCEVInitRewriter(const Loop *L, ScalarEvolution &SE)
-      : SCEVRewriteVisitor(SE), L(L) {}
+  explicit SCEVInitRewriter(const Loop *L, ScalarEvolution &SE,
+                            bool IgnoreOtherLoops)
+      : SCEVRewriteVisitor(SE), L(L), IgnoreOtherLoops(IgnoreOtherLoops) {}
 
   const Loop *L;
+  const bool IgnoreOtherLoops;
   bool Valid = true;
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43498.135007.patch
Type: text/x-patch
Size: 1791 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180220/34b0951f/attachment.bin>


More information about the llvm-commits mailing list