Table of Contents
Fetching ...

Idempotent Slices with Applications to Code-Size Reduction

Rafael Alvarenga de Azevedo, Daniel Augusto Costa de Sa, Rodrigo Caetano Rocha, Fernando Magno Quintão Pereira

TL;DR

The paper describes how identifying and extracting idempotent backward slices enables a sparse code-size reduction optimization; that is, one capable of merging non-contiguous sequences of instructions within the control-flow graph of a single function or across functions.

Abstract

Given a value computed within a program, an idempotent backward slice with respect to this value is a maximal subprogram that computes it. An informal notion of an idempotent slice has previously been used by Guimaraes et al. to transform eager into strict evaluation in the LLVM intermediate representation. However, that algorithm is insufficient to be correctly applied to general control-flow graphs. This paper addresses these omissions by formalizing the notion of idempotent backward slices and presenting a sound and efficient algorithm for extracting them from programs in Gated Static Single Assignment (GSA) form. As an example of their practical use, the paper describes how identifying and extracting idempotent backward slices enables a sparse code-size reduction optimization; that is, one capable of merging non-contiguous sequences of instructions within the control-flow graph of a single function or across functions. Experiments with the LLVM test suite show that, in specific benchmarks, this new algorithm achieves code-size reductions up to -7.24% on programs highly optimized by the -Os sequence of passes from clang 17.

Idempotent Slices with Applications to Code-Size Reduction

TL;DR

The paper describes how identifying and extracting idempotent backward slices enables a sparse code-size reduction optimization; that is, one capable of merging non-contiguous sequences of instructions within the control-flow graph of a single function or across functions.

Abstract

Given a value computed within a program, an idempotent backward slice with respect to this value is a maximal subprogram that computes it. An informal notion of an idempotent slice has previously been used by Guimaraes et al. to transform eager into strict evaluation in the LLVM intermediate representation. However, that algorithm is insufficient to be correctly applied to general control-flow graphs. This paper addresses these omissions by formalizing the notion of idempotent backward slices and presenting a sound and efficient algorithm for extracting them from programs in Gated Static Single Assignment (GSA) form. As an example of their practical use, the paper describes how identifying and extracting idempotent backward slices enables a sparse code-size reduction optimization; that is, one capable of merging non-contiguous sequences of instructions within the control-flow graph of a single function or across functions. Experiments with the LLVM test suite show that, in specific benchmarks, this new algorithm achieves code-size reductions up to -7.24% on programs highly optimized by the -Os sequence of passes from clang 17.
Paper Structure (45 sections, 3 theorems, 2 equations, 12 figures, 5 tables)

This paper contains 45 sections, 3 theorems, 2 equations, 12 figures, 5 tables.

Key Result

Lemma 4.1

Let an Idempotent Backward Slice $S$ be constructed by a backward dependence traversal from a criterion $v$, identifying a slice region $V_s$. Then, there exists a unique block $b_{\mathit{entry}} \in V_s$ that dominates every other block in $V_s$.

Figures (12)

  • Figure 1: Examples of idempotent and non-idempotent instruction sequences in LLVM IR.
  • Figure 2: (a) Program with a slice criterion: the instruction $s = s + 1$. (b) Dense slice, adapted from Blazy15. (c) Program in Static Single-Assignment form. (d) Program in Gated Static Single-Assignment form. (e) Idempotent backward slice with respect to SSA variable $s_3$. (f) Idempotent backward slice with respect to SSA variable $x_2$.
  • Figure 3: (a) The four rules used by Rodrigues16 to infer data and control dependencies. (b) A control-flow graph showing a sub-structure that causes campos2023's algorithm to miss block $B_2$ in the backward slice with regards to criterion $x_3$. (c) The backward dependency graph built for the slice criterion $x_3$.
  • Figure 4: (a) SSA CFG annotated with gating-path predicates. (b) GSA form after $\phi$-elimination. (c) Backward dependence graph of variable x3.
  • Figure 5: (a) GSA program (reproduced from Figure \ref{['fig_exampleSlices']}). (b) Dependence graph derived from def-use chains with loop depths. Variables defined by $\mu$-functions are marked in dark gray: they work as stop criteria. (c--e) Backward dependence graphs for s3, x2, and p0, respectively.
  • ...and 7 more figures

Theorems & Definitions (16)

  • Definition 1: Idempotent Execution
  • Example 1
  • Definition 2: Idempotent Backward Slice
  • Example 2
  • Definition 3: Sparse Backward Dependence Graph
  • Example 3
  • Example 4
  • Example 5
  • Example 6
  • Example 7
  • ...and 6 more