[PATCH] D92153: [SCEV] Move assertion checks into isKnownPredicateAt

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 25 22:32:56 PST 2020


mkazantsev created this revision.
mkazantsev added reviewers: lebedev.ri, nikic, skatkov.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
mkazantsev requested review of this revision.

We can benefit from assumes in `isKnownPredicateAt`, not only in
`isLoopBackedgeGuardedByCond`. The proof there also may become
more powerful from using the context.


https://reviews.llvm.org/D92153

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp


Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -9503,7 +9503,18 @@
 bool ScalarEvolution::isKnownPredicateAt(ICmpInst::Predicate Pred,
                                          const SCEV *LHS, const SCEV *RHS,
                                          const Instruction *Context) {
-  // TODO: Analyze guards and assumes from Context's block.
+  // Check conditions due to any @llvm.assume intrinsics.
+  for (auto &AssumeVH : AC.assumptions()) {
+    if (!AssumeVH)
+      continue;
+    auto *CI = cast<CallInst>(AssumeVH);
+    if (!DT.dominates(CI, Context))
+      continue;
+
+    if (isImpliedCond(Pred, LHS, RHS, CI->getArgOperand(0), false, Context))
+      return true;
+  }
+
   return isKnownPredicate(Pred, LHS, RHS) ||
          isBasicBlockEntryGuardedByCond(Context->getParent(), Pred, LHS, RHS);
 }
@@ -9890,18 +9901,6 @@
       return true;
   }
 
-  // Check conditions due to any @llvm.assume intrinsics.
-  for (auto &AssumeVH : AC.assumptions()) {
-    if (!AssumeVH)
-      continue;
-    auto *CI = cast<CallInst>(AssumeVH);
-    if (!DT.dominates(CI, Latch->getTerminator()))
-      continue;
-
-    if (isImpliedCond(Pred, LHS, RHS, CI->getArgOperand(0), false))
-      return true;
-  }
-
   // If the loop is not reachable from the entry block, we risk running into an
   // infinite loop as we walk up into the dom tree.  These loops do not matter
   // anyway, so we just return a conservative answer when we see them.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92153.307758.patch
Type: text/x-patch
Size: 1603 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201126/335c400c/attachment.bin>


More information about the llvm-commits mailing list