How to solve circular dependency between passes


I am working on a case for loop interchange, and discovered that to enable loop interchange in my case, I have to run it before LICM and after Induction Variable Simplify. So the good order for me is: Induction Variable Simplify → Loop Interchange → LICM. However, I also found cases where Induction Variable Simplify works better after LICM, and running Induction Variable Simplify after LICM again still results in suboptimal result.

Has anyone encountered similar dependency problem when reordering passes? If so, can you kindly share your solution or suggestion?



This sounds like a typical 'phase ordering' problem and unfortunately
there is no solution to it without improving the passes themselves.
For your case IndVarSimplify and LICM are considered canonicalization
passes. Any pass should be designed to work best on canonicalized IR.
In practice, however, this is not true [1]. In particular,
LoopInterchange is sensitive to dependencies created by LICM hoisting
code out of the inner loop. I don't think it is solvable in a
satisfying with the current pass infrastructure.