GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
i386

i386: Fix ICE on out of bounds vector elt access [PR126446]

Fixes compiler ICE when accessing vector elements with out-of-bounds or negative indices.

This commit resolves a compiler Internal Compiler Error (ICE) on x86_64 when accessing vector elements with out-of-bounds or negative indices. The issue occurred because the index check, which uses poly_uint64, failed for negative long long values, leading to incorrect optimization. The fix ensures that out-of-bounds accesses to vector elements are handled gracefully by emitting a no-op move, preventing the ICE and avoiding undefined behavior.

In Details

This patch addresses an ICE in the isel pass on x86_64 when optimizing vector element accesses using VEC_SET. The poly_int_tree_p check for bounds fails for negative long long indices, allowing them to be converted to .VEC_SET and subsequently causing issues during expansion. The fix modifies ix86_expand_vector_set to emit a no-op mov instruction when the element index is out of bounds, thus avoiding compilation-time UB and the ICE. A new test case avx2-pr126446.c is added.

For Context
ICE
Internal Compiler Error. An unexpected condition encountered by the compiler during the compilation process, typically indicating a bug in the compiler itself. The compilation is aborted when an ICE occurs.
vector element access
Accessing individual components within a vector data type. Vector types are common in SIMD (Single Instruction, Multiple Data) instructions and allow operations on multiple data elements simultaneously.
isel pass
Instruction Selection pass. A compiler optimization pass responsible for mapping intermediate representation (IR) instructions to specific machine instructions for the target architecture.
poly_uint64
A data type used in GCC to represent arbitrary-precision unsigned integers, often employed for calculations involving loop invariants or complex index computations.
VEC_SET
An internal GCC instruction or operation representing the setting of a specific element within a vector. It's part of the GIMPLE intermediate representation.
undefined behavior (UB)
Behavior that results from an implementation whose behavior is not explicitly defined by the C++ standard. Compilers often assume UB does not occur, which can lead to unexpected optimizations or errors.
Filed Under: x86vectorizationcompiler bugoptimization