FRIDAY, AUGUST 14, 2026
c++ Performance Win
Enable trial constexpr folding for INIT_EXPR in C++.
C++ compiler now trial-folds INIT_EXPR for constexpr evaluation, fixing test failures.
This patch enables trial constexpr folding for INIT_EXPR in the C++ front-end, mirroring existing support for TARGET_EXPR. This change addresses test failures in is_constant_evaluated3{a,b}.C by correctly handling local copy-initialization, which is represented as an INIT_EXPR.
In Details
The cp_fold_r function in cp-gimplify.cc now includes logic for case INIT_EXPR to perform trial maybe_constant_init folding, similar to how TARGET_EXPR is handled. This is intended to fix g++.dg/opt/is_constant_evaluated3{a,b}.C testcases by allowing constexpr evaluation of initializers for local variables that use copy-initialization.
For Context
- constexpr
- A C++ keyword that denotes that a variable or function's value can be determined at compile time. This enables compile-time evaluation, improving performance.
- INIT_EXPR
- An expression in GCC's internal representation (GIMPLE) that represents initialization of a variable or object.
- TARGET_EXPR
- An expression in GCC's internal representation (GIMPLE) that represents initialization of a target object, often used in contexts like
__builtin_memcpyor aggregate initialization. - constant evaluation
- The process by which the compiler determines the value of an expression at compile time rather than at runtime.
- GIMPLE
- GCC's internal representation (IR) used between the front-end and the optimization passes. It's a three-address code form.