[PATCH] D87094: [CodeMoverUtils]Add option to skip control flow equivalence checks when sure

rithik sharma via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 3 09:03:42 PDT 2020


RithikSharma created this revision.
RithikSharma added reviewers: Whitney, bmahjour, etiotto.
RithikSharma added a project: LLVM.
Herald added subscribers: llvm-commits, hiraditya.
RithikSharma requested review of this revision.

This patch adds option to skip control flow equivalence checks, there are passes which has code-motion in control flow equivalent blocks and due to unavailability of PDT, it doesn't allow us to use CodeMoverUtils in it. The code-motion client can pass true for skipping control flow equivalence and can also pass PDT as an argument instead of true/false if it is available.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87094

Files:
  llvm/include/llvm/Transforms/Utils/CodeMoverUtils.h
  llvm/lib/Transforms/Utils/CodeMoverUtils.cpp


Index: llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
+++ llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
@@ -306,12 +306,21 @@
     getNextInsts(*CurInst, WorkList);
   }
 }
-
 bool llvm::isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint,
                               DominatorTree &DT, const PostDominatorTree *PDT,
                               DependenceInfo *DI) {
-  // Skip tests when we don't have PDT or DI
-  if (!PDT || !DI)
+  // TODO remove this limitation.
+  if (!isControlFlowEquivalent(I, InsertPoint, DT, *PDT))
+    return reportInvalidCandidate(I, NotControlFlowEquivalent);
+  return isSafeToMoveBefore(I, InsertPoint, DT, true, DI);
+}
+
+bool llvm::isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint,
+                              DominatorTree &DT,
+                              bool skipControlFlowEquivalence,
+                              DependenceInfo *DI) {
+  // Skip tests when we don't have DI
+  if (!skipControlFlowEquivalence || !DI)
     return false;
 
   // Cannot move itself before itself.
@@ -328,10 +337,6 @@
   if (I.isTerminator())
     return reportInvalidCandidate(I, NotMovedTerminator);
 
-  // TODO remove this limitation.
-  if (!isControlFlowEquivalent(I, InsertPoint, DT, *PDT))
-    return reportInvalidCandidate(I, NotControlFlowEquivalent);
-
   if (!DT.dominates(&InsertPoint, &I))
     for (const Use &U : I.uses())
       if (auto *UserInst = dyn_cast<Instruction>(U.getUser()))
Index: llvm/include/llvm/Transforms/Utils/CodeMoverUtils.h
===================================================================
--- llvm/include/llvm/Transforms/Utils/CodeMoverUtils.h
+++ llvm/include/llvm/Transforms/Utils/CodeMoverUtils.h
@@ -36,6 +36,11 @@
                              const DominatorTree &DT,
                              const PostDominatorTree &PDT);
 
+/// Return true if \p I can be safely moved before \p InsertPoint.
+bool isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint,
+                        DominatorTree &DT, bool skipControlFlowEquivalence,
+                        DependenceInfo *DI = nullptr);
+
 /// Return true if \p I can be safely moved before \p InsertPoint.
 bool isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint,
                         DominatorTree &DT,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87094.289732.patch
Type: text/x-patch
Size: 2400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200903/6ad5e938/attachment.bin>


More information about the llvm-commits mailing list