This is an archive of the discontinued LLVM Phabricator instance.

[CodeMoverUtils] Enhance isSafeToMoveBefore() when control flow equivalence is satisfied
ClosedPublic

Authored by congzhe on Sep 24 2021, 4:36 PM.

Details

Summary

With improved analysis in determining CFG equivalence that does not require strict dominance and post-dominance conditions, we now relax isSafeToMoveBefore() such that an instruction I can be moved before InsertPoint even if they do not strictly dominate each other, as long as they follow the same control flow path.

For example, we can move Instruction 0 before Instruction 1, and vice versa.

if (cond1)
   // Instruction 0: %add = add i32 1, 2
if (cond1)
   // Instruction 1: %add2 = add i32 2, 1

Diff Detail

Event Timeline

congzhe created this revision.Sep 24 2021, 4:36 PM
congzhe requested review of this revision.Sep 24 2021, 4:36 PM
Whitney added inline comments.Sep 27 2021, 7:09 AM
llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
440

How about adding assert(isControlFlowEquivalent(*ThisBlock, *OtherBlock, *DT, *PDT));?

446

typo: any or them

congzhe updated this revision to Diff 375372.Sep 27 2021, 12:43 PM
congzhe marked 2 inline comments as done.
congzhe added inline comments.
llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
440

Thanks, all comments addressed.

Whitney accepted this revision.Sep 27 2021, 12:50 PM

One minor comment, other than that LGTM.

llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
440

make sure to put some kind of error message in the assertion statement

https://llvm.org/docs/CodingStandards.html#assert-liberally

This revision is now accepted and ready to land.Sep 27 2021, 12:50 PM
congzhe updated this revision to Diff 375380.Sep 27 2021, 1:05 PM
congzhe marked an inline comment as done.
This revision was landed with ongoing or failed builds.Sep 27 2021, 3:38 PM
This revision was automatically updated to reflect the committed changes.
congzhe marked an inline comment as done.