]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: P2280R4 and speculative constexpr folding [PR119387]
authorPatrick Palka <ppalka@redhat.com>
Thu, 3 Apr 2025 20:33:46 +0000 (16:33 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 3 Apr 2025 20:33:46 +0000 (16:33 -0400)
commita926345f22b500a2620adb83e6821e01fb8cc8fd
treeb45d81f2366b59f3ff3e107a7eb5b752fe7522fb
parentc669ab0a866697577fec0c8c2e662640c4be4c94
c++: P2280R4 and speculative constexpr folding [PR119387]

Compiling the testcase in this PR uses 2.5x more memory and 6x more
time ever since r14-5979 which implements P2280R4.  This is because
our speculative constexpr folding now does a lot more work trying to
fold ultimately non-constant calls to constexpr functions, and in turn
produces a lot of garbage.  We do sometimes successfully fold more
thanks to P2280R4, but it seems to be trivial stuff like calls to
std::array::size or std::addressof.  The benefit of P2280 therefore
doesn't seem worth the cost during speculative constexpr folding, so
this patch restricts the paper to only manifestly-constant evaluation.

PR c++/119387

gcc/cp/ChangeLog:

* constexpr.cc (p2280_active_p): New.
(cxx_eval_constant_expression) <case VAR_DECL>: Use it to
restrict P2280 relaxations.
<case PARM_DECL>: Likewise.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/constexpr.cc