GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/genextract Performance Win

genextract: Drive insn_extract from operand path table

Replaces a large switch statement in insn_extract with a data-driven table lookup, reducing code size.

The genextract tool is responsible for extracting operands from instruction patterns. Previously, it used a large switch statement where each case corresponded to an instruction, leading to excessive labels and large generated code. This commit replaces the switch statement with a data-driven approach. It uses tables to store extraction methods, operand counts, and path strings, allowing insn_extract to walk these paths dynamically. This change significantly reduces the size of the generated code, particularly on architectures like AArch64 and RISC-V.

In Details

The genextract component of GCC translates RTL patterns into C code for operand extraction. Historically, insn_extract used a monolithic switch statement mapping instruction codes to operand extraction logic. This commit replaces that switch with a table-driven approach. extract_method_of_code maps instruction codes to extraction methods, extract_methods provides metadata for each method (like operand count and offsets), and extract_paths stores the actual path strings (e.g., '1c' for XEXP(pat, 1), element 2). This reduces code size by eliminating redundant case labels and shared ex…

For Context
genextract
A GCC internal component that generates C code for extracting operands from RTL (Register Transfer Language) patterns.
insn_extract
The function generated by genextract that performs the actual extraction of operands from an instruction's RTL representation.
RTL
Register Transfer Language, an intermediate representation used by GCC to represent program code during compilation.
path string
A compact string representation used by genextract to describe how to navigate an RTL structure (e.g., '1c' for XEXP(pat, 1), element 2).
XVECEXP
An RTL construct representing an element within a vector (e.g., an array or a list) in an instruction pattern.
XEXP
An RTL construct representing an expression or operand within an instruction pattern.
Filed Under: gcccode generationoptimizationaarch64riscv