[RFC] Reassociate and loops

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 28 17:23:20 PDT 2017


I’ve stumbled upon an issue (in a real program) wherein Reassociate can inadvertently sink a huge number of instructions into loops. This happens because the part of the pass that re-inserts changed expressions into the function (when an expression is nontrivially modified) just inserts it all right before the leaf of the chain, which can potentially move things into inner loops.

In the upstream pass pipeline, Reassociate is used before LICM. In our pass pipeline, we do it more like this:

// simplification passes, including instcombine, CSE, DCE, reassociate, etc

// loop unrolling and other loop passes

// simplification passes again, including instcombine, CSE, DCE, reassociate, etc   <— in the test case, the problem occurs here.

as far as i can tell, there are two possible solutions to this —
1) I wrote a modification to Reassociate that fixes the problem by using LoopInfo when inserting instructions. This makes it require LoopInfo/DT, but this shouldn’t increase computation in the default pass pipeline because the following passes -also- require LoopInfo and Reassociate doesn’t clobber it.
2) Just deem that reassociate, by design, should be run prior to LICM.

thoughts?

—escha


More information about the llvm-commits mailing list