diff options
author | Patrick Palka <ppalka@redhat.com> | 2025-04-13 11:04:46 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2025-04-13 11:04:46 -0400 |
commit | 5869a881442aa4214d5deed7cfe0d352bcca1fd4 (patch) | |
tree | 3fded1986eda8275f3c4b28981763d5329157821 /libjava/java | |
parent | 962c3d69f189f6fa451153faf3ce261c50d23d5a (diff) | |
download | gcc-5869a881442aa4214d5deed7cfe0d352bcca1fd4.zip gcc-5869a881442aa4214d5deed7cfe0d352bcca1fd4.tar.gz gcc-5869a881442aa4214d5deed7cfe0d352bcca1fd4.tar.bz2 |
c++: improve constexpr call caching [PR115639]
For the testcase from this PR, checking
static_assert(0 == big_calc());
takes twice as much time as
constexpr int ret = big_calc();
static_assert(0 == ret);
ultimately because in the former, we first constant evaluate big_calc()
with mce_unknown (as part of warning-dependent folding from
cp_build_binary_op). We then constant evaluate it a second time, with
mce_true, during finish_static_assert. The result of the first
evaluation isn't reused because of the different mce_value, which in
general can give a different result.
But big_calc() here doesn't depend on mce_value at all (i.e. there's no if
consteval or __builtin_is_constant_evaluated calls, nested or otherwise)
so we should be able to reuse the result in such cases. Specifically if a
constexpr call with mce_unknown succeeds, we can safely reuse the result
during a subsequent mce_true or mce_false evaluation.
This patch implements this by also caching a successful mce_unknown call
result into the corresponding mce_true and mce_false slots, so that such
a subsequent evaluation effectively reuses the mce_unknown result. To
make it more convenient to access the cache slot for the same call with
different mce_value, this patch gives each constexpr_call entry three
result slots, one per mce_value, instead of having a distinct
constexpr_call entry for each mce_value. And we can no longer use
NULL_TREE to denote the call is in progress; instead use unknown_type_node.
After this patch compile time for the above two fragments is the same.
PR c++/115639
gcc/cp/ChangeLog:
* constexpr.cc (struct constexpr_call): Add NSDMIs to each
field. Replace 'result' data member with 3-element 'results'
array and a 'result' accessor function. Remove
'manifestly_const_eval' data member.
(constexpr_call_hasher::equal): Adjust after constexpr_call
layout change.
(cxx_eval_call_expression): Likewise. Define some local
variables closer to their first use. Use unknown_type_node
instead of NULL_TREE as the "in progress" result. After
successully evaluating a call with mce_unknown, also cache the
result in the corresponding mce_true and mce_false slots.
Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'libjava/java')
0 files changed, 0 insertions, 0 deletions