aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
diff options
context:
space:
mode:
authorRithik Sharma <rithiksh02@gmail.com>2020-05-27 18:00:06 +0000
committerWhitney Tsang <whitneyt@ca.ibm.com>2020-05-27 18:02:06 +0000
commiteadf2959567c89bebff153feac873cbc1b71eb04 (patch)
tree7c94d08e1bb3f32223eff60cec82cc62056aec8f /llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
parentb9c6871a9570975827dc0bbeb39131c99c8daf8e (diff)
downloadllvm-eadf2959567c89bebff153feac873cbc1b71eb04.zip
llvm-eadf2959567c89bebff153feac873cbc1b71eb04.tar.gz
llvm-eadf2959567c89bebff153feac873cbc1b71eb04.tar.bz2
[CodeMoverUtils] Use dominator tree level to decide the direction of
code motion Summary: Currently isSafeToMoveBefore uses DFS numbering for determining the relative position of instruction and insert point which is not always correct. This PR proposes the use of Dominator Tree depth for the same. If a node is at a higher level than the insert point then it is safe to say that we want to move in the forward direction. Authored By: RithikSharma Reviewer: Whitney, nikic, bmahjour, etiotto, fhahn Reviewed By: Whitney Subscribers: fhahn, hiraditya, llvm-commits Tag: LLVM Differential Revision: https://reviews.llvm.org/D80084
Diffstat (limited to 'llvm/lib/Transforms/Utils/CodeMoverUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/CodeMoverUtils.cpp17
1 files changed, 6 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp b/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
index 383e749..4583ff7 100644
--- a/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
+++ b/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
@@ -317,25 +317,20 @@ bool llvm::isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint,
if (!isControlFlowEquivalent(I, InsertPoint, DT, PDT))
return reportInvalidCandidate(I, NotControlFlowEquivalent);
- OrderedInstructions OI(&DT);
- DT.updateDFSNumbers();
- const bool MoveForward = OI.dfsBefore(&I, &InsertPoint);
- if (MoveForward) {
- // When I is being moved forward, we need to make sure the InsertPoint
- // dominates every users. Or else, a user may be using an undefined I.
+ if (!DT.dominates(&InsertPoint, &I))
for (const Use &U : I.uses())
if (auto *UserInst = dyn_cast<Instruction>(U.getUser()))
if (UserInst != &InsertPoint && !DT.dominates(&InsertPoint, U))
return false;
- } else {
- // When I is being moved backward, we need to make sure all its opernads
- // dominates the InsertPoint. Or else, an operand may be undefined for I.
+ if (!DT.dominates(&I, &InsertPoint))
for (const Value *Op : I.operands())
if (auto *OpInst = dyn_cast<Instruction>(Op))
- if (&InsertPoint == OpInst || !OI.dominates(OpInst, &InsertPoint))
+ if (&InsertPoint == OpInst || !DT.dominates(OpInst, &InsertPoint))
return false;
- }
+ OrderedInstructions OI(&DT);
+ DT.updateDFSNumbers();
+ const bool MoveForward = OI.domTreeLevelBefore(&I, &InsertPoint);
Instruction &StartInst = (MoveForward ? I : InsertPoint);
Instruction &EndInst = (MoveForward ? InsertPoint : I);
SmallPtrSet<Instruction *, 10> InstsToCheck;