u/FloweyTheFlower420

I am looking for literature on a class of optimizations that are easy to express in classic CFG/SSA form but seem awkward in SoN IR.

In a CFG/SSA representation, control-flow dominance gives us useful facts about the predicates that hold at a given instruction. For example, inside an if (c == 2) block, an expression like x / c may be simplified to x >> 1 or another equivalent form, depending on rounding semantics. This also enables elimination of redundant conditionals. I do not think SCCP captures this generally, at least not in the form presented in Simple.

A second case is expression duplication across branches: if a complex expression X is used in both arms of an if/else, it can sometimes be profitable to duplicate X into each branch so that each copy can be simplified using branch-specific predicates. This is straightforward to detect in CFG/SSA, but much harder in SoN IR before scheduling.

More generally, I am interested in optimizations whose profitability depends on scheduling or placement relative to control flow. In principle, one could schedule first, perform these optimizations, and then reschedule, but that feels somewhat at odds with the SoN philosophy.

Is there existing work on this, or a standard way to handle it?

reddit.com
u/FloweyTheFlower420 — 11 days ago

Click Cliff has a paper on global code motion, but the algorithm relies on the control flow graph being reducible. The general idea of the algorithm is to schedule instructions out of loops and inside conditional statements. Is it possible to generalize this algorithm to irreducible control flow? In particular, I think as long as there exists some notion of basic block execution frequency (which is what loop depth + if depth approximate), it should be possible to generalize this algorithm, but I'm not quite sure how one would go about implementing this.

Does anyone have some suggestions on how I would go about doing this? I think I can reference what LLVM does in BlockFrequencyInfo/BlockFrequencyAnalysis, but I'm concerned whether the GCM algorithm will fully generalize.

reddit.com
u/FloweyTheFlower420 — 16 days ago