Introduction
Instruction selection is a critical phase in compiler optimization, where high-level intermediate representation (IR) operations are mapped to specific hardware instruction set architecture (ISA) instructions. Traditionally, this mapping relies on a library of rewrite rules. However, manually authoring these libraries is an arduous and error-prone task. While automated synthesis tools have emerged, they often struggle with "many-to-many" mappings, produce redundant rules, and lack the efficiency to find the lowest-cost implementations in a reasonable timeframe.
This paper presents a novel framework, Generalized Component-Based Program Synthesis (GCBPS), designed to automatically generate efficient many-to-many rewrite rules while drastically reducing synthesis time through aggressive pruning techniques.
The Challenge of Redundancy in Synthesis
The primary bottleneck in automated rule synthesis is the sheer volume of redundant solutions. The authors discovered that in a standard synthesis run, approximately 99.5% of generated rules are either duplicates or composites.
- Duplicates are rules that are functionally identical but structurally different (e.g., due to commutativity).
- Composites are complex rules that can be decomposed into a sequence of simpler, already-discovered rules.
By identifying these redundancies during the synthesis process rather than as a post-processing step, the search space can be significantly narrowed.
Methodology: GCBPS and Optimized Algorithms
The GCBPS framework synthesizes two functionally equivalent programs simultaneously: one in the IR and one in the target ISA. To handle the complexity of this search, the authors introduced two key algorithms:
genAll: This iterative algorithm employs an "AllSAT" approach to enumerate unique rewrite rules. It incorporates constraints into the SMT solver to block the discovery of duplicate and composite rules. This structural pruning ensures that the solver only spends time on truly novel mappings.
genAllLC(Lowest Cost): Building upongenAll, this version introduces a cost metric (such as code size or energy consumption). By exploring ISA instruction combinations in order of increasing cost, the algorithm can terminate the search for a specific IR pattern once the cheapest ISA implementation is found. This "cost-first" search allows the system to mathematically prove that more expensive alternatives are unnecessary.
Key Results and Performance
The impact of these pruning strategies is profound. When evaluated against a state-of-the-art baseline (IterativeCEGIS), the proposed methods demonstrated massive performance gains across various instruction sets, including RISC-like and specialized linear algebra ISAs.
As shown in the results, the genAll algorithm achieved speedups of up to 768×, while the cost-aware genAllLC reached staggering speedups of over 4004×. Beyond raw speed, these optimizations enabled the discovery of unique rules that the baseline method failed to find due to timeouts. For instance, in one test case (ISA 1b), the new framework identified five additional unique rules that were previously unreachable.
Furthermore, the authors highlighted the importance of structural equivalence over simple observational equivalence. In the context of compiler pattern matching, the data dependency structure of a rule is often more relevant than just its output behavior, leading to more robust and useful rule libraries.
Limitations and Future Directions
While GCBPS represents a significant leap forward, several areas for future development remain. The current synthesis is restricted to loop-free code and utilizes simplified cost models that do not yet account for complex hardware behaviors like instruction pipelining or port contention.
Future work aims to extend the framework to support memory operations, control flow, and instructions with multiple outputs. Ultimately, the goal is to integrate these synthesized rule libraries directly into production-grade compilers like LLVM, enabling automated, hardware-specific optimization at scale.
Summary updated