Handle STRING_CSTs and RAW_DATA_CSTs in range_from_readonly_var
Improves range folding to correctly handle string and raw data constants.
This commit enhances the range_from_readonly_var function in gimple-fold-range to properly handle STRING_CST and RAW_DATA_CST operands. Previously, these types were not fully supported, potentially leading to incorrect folding of constants that represent string literals or embedded raw data. The changes allow the compiler to accurately interpret and fold these constant types, improving optimization opportunities for string initializers and embedded data.
In Details
This commit modifies gimple-range-fold.cc, specifically within ctor_ref_range::accumulate_range and ctor_ref_range::accumulate_range_from_component_ref, to support STRING_CST and RAW_DATA_CST in addition to CONSTRUCTOR. This is relevant for folding constant array initializers into single constants. For these types, the index range is checked against the byte representation, and if a match occurs, a wide_int is created via union, avoiding intermediate build_int_cst calls. The code now handles potential sign or zero extension for CHAR_BIT precision integral types derived from…
- gimple-fold-range
- A GCC optimization pass that folds constant values within a specified range, often applied to array initializers or string literals.
- STRING_CST
- An internal GCC representation for a string constant.
- RAW_DATA_CST
- An internal GCC representation for a constant block of raw data, often used for embedded data or large initializers.
- wide_int
- An arbitrary-precision integer type used within GCC for representing integer constants that may exceed the native machine word size.
- CHAR_BIT
- A C preprocessor macro defining the number of bits in a byte.
- CPP_EMBED
- A C++ preprocessor directive that allows embedding raw binary data into a program.