Abstract
Redundancy elimination is a key optimization direction, and loop nests are the main optimization target in modern compilers. Previous work on redundancy elimination of array computations in loop nests lacks universality. These approaches either focus on specific computation patterns or fail to recognize redundancies with complex structures. This paper proposes RACE (Redundant Array Computation Elimination), a more general redundancy elimination technique. RACE utilizes a novel two-level scheme to identify the data reuse between array references and the computation redundancies between expressions. It traverses the expression trees in loop nests to detect redundancies hierarchically in linear time and generates efficient code with optimized auxiliary arrays that store redundant computation results. Furthermore, RACE supports the expression reassociation with various aggressive strategies to improve the redundancy opportunities. Experimental results demonstrate the effectiveness of RACE.
Introduction
Modern compilers are highly effective at Common Subexpression Elimination (CSE) within local code blocks. However, they frequently struggle with loop-carried redundancies involving array computations. In scientific kernels like 3D stencils, a calculation performed at index $(i, j)$ often computes the exact same sub-expression required at $(i+1, j)$ in a subsequent iteration. Standard optimizations fail to recognize these because the absolute array indices differ, even though the relative access patterns are identical.
Previous attempts to address this were either restricted to specific stencil patterns or suffered from $O(n^2)$ complexity, making them impractical for large-scale production code. RACE (Redundant Array Computation Elimination) addresses these gaps by providing a general, linear-time solution for identifying and removing these hidden redundancies across loop iterations.
Methodology
The core of RACE is a two-level identification scheme that avoids the need for exhaustive pair-wise comparisons:
- Reference Pattern Identification (RPI): This level analyzes array accesses to determine if two references (e.g.,
A[i]andA[i+1]) share the same access pattern or "lattice," regardless of their specific offsets. - Expression Redundancy Identification (ERI): This level combines the RPI of operands with the relative distance (delta) between them to create a unique hash for an expression. If two expressions share the same ERI, they are redundant.
RACE applies these hashes during a hierarchical, bottom-up traversal of expression trees. When a redundancy is identified, RACE allocates an auxiliary array to store the result for reuse. To minimize the memory footprint of these new arrays, RACE employs Array Contraction. This technique reduces multi-dimensional auxiliary arrays into scalars or "1.5D" buffers using a pipelining approach, ensuring only the necessary data slices are kept in memory.
Experimental Results
The authors evaluated RACE using high-performance computing (HPC) benchmarks, including the Parallel Ocean Program (POP), the Weather Research and Forecasting (WRF) model, and various stencil kernels on Intel Xeon and AMD EPYC platforms.
Key Performance Metrics
- Significant Speedups: RACE achieved a 3.06x speedup on the POP
calc_tpointskernel and a 3.96x speedup on derivative stencils. - Operation Reduction: In the POP benchmark, expensive trigonometric calls (
sin/cos) were reduced from 16 to 4 per iteration. In thederivativestencil, static multiplications were slashed from 297 to 101. - Comparison with State-of-the-Art: RACE outperformed Enhanced Scalar Replacement (ESR) in 14 out of 15 test cases, primarily due to its ability to look across outer loop iterations and handle complex expression reassociations.
Conclusion
RACE introduces a robust, linear-time framework for eliminating redundant array computations. By utilizing hierarchical hashing and aggressive expression reassociation, it uncovers optimization opportunities that traditional compilers miss. While the introduction of auxiliary arrays increases memory pressure, RACE's array contraction techniques effectively mitigate this overhead, delivering substantial performance gains for complex scientific workloads.
Summary updated