right way for setting PreserveLCSSA with new pass manager


mustPreserveAnalysisID(LCSSAID) cannot be used with the new pass manager, so what is the right way for querying it? FunctionAnalysisManager::getCachedResult(F) will not work, since LCSSAPass does not have a result. Moreover, it is not an analysis J



Hi Slava,

we don’t preserve LCSSA in the new PM. If you need it you have to rerun LCSAA before your pass.


Hi Philip,

If I want to use InsertPreheaderForLoop(), I need to pass PreserveLCSSA parameter to it. If I get it right, I should use mustPreserveAnalysisID(LCSSAID) with the old pass manager and pass ‘false’ explicitly with the new pass manager. Does it sound right?



I think there is a conflation here of slightly different things causing confusion.

LCSSA is a form of IR that is useful to some passes.

There are several utilities that can preserve LCSSA form when called on IR such as InsertPreheaderForLoop. When calling these utilities, you can choose whether or not you want the utility to preserve that form. All this does is change how the utility behaves in the face of LCSSA – typically by adding checks for those special constructs and preserving them when present.

Some passes need the IR to be in LCSSA form to work correctly (often because anything else would introduce unscalable algorithmic complexity). You can put it into this form with an LCSSA pass (or by directly calling utility functions to do this in your pass), and when in this form you might use the above to preserve it while your pass works on that form.

The old pass manager also has a concept of both requiring and preserving an LCSSA “analysis”. This is a confusing concept because LCSSA is not an analysis, it is a form of IR and a transformation pass to put IR into that form. However, the old pass manager allows you to use its concept of “analysis preservation” and “analysis requirement” to automatically control when to run the LCSSA transformation pass in order to have the IR in LCSSA form for the passes that expect this form. In order to not constantly have a pass automatically scheduled to re-form LCSSA after every transformation, many passes preserve this “analysis” with the pass manager (by ensuring IR that starts off in LCSSA form remains in it after the pass) using the API you mention and the LCSSAID pass “ID”. Most old pass manager loop passes fall into this category.

However, this automatic behavior is convenient at times, but has also historically been confusing and error prone. So the new pass manager takes a different approach. There, loop passes are automatically given IR in LCSSA form and the loop pass manager (rather than any analysis) both introduces this form and ensures that it is not removed. Every loop pass in the new PM is required to preserve LCSSA form (either directly much like the bool parameters trigger in utility code, or by recreating it after any transformations that could have broken LCSSA form). Other kinds of passes simply call a utility to put the IR into LCSSA form at the start of their pass.

Hope this helps some in explaining the background and the different aspects of this.