* [Bug c++/111660] Compilation of constexpr function returning enum takes exponential time with -std=c++2a
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
@ 2023-10-02 1:16 ` envia at envia dot pe.kr
2023-10-02 1:17 ` envia at envia dot pe.kr
` (14 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: envia at envia dot pe.kr @ 2023-10-02 1:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
--- Comment #1 from Hwang Joonhyung <envia at envia dot pe.kr> ---
Created attachment 56025
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56025&action=edit
It took 138 seconds.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] Compilation of constexpr function returning enum takes exponential time with -std=c++2a
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
2023-10-02 1:16 ` [Bug c++/111660] " envia at envia dot pe.kr
@ 2023-10-02 1:17 ` envia at envia dot pe.kr
2023-10-02 1:18 ` envia at envia dot pe.kr
` (13 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: envia at envia dot pe.kr @ 2023-10-02 1:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
--- Comment #2 from Hwang Joonhyung <envia at envia dot pe.kr> ---
Created attachment 56026
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56026&action=edit
It took 70 seconds.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] Compilation of constexpr function returning enum takes exponential time with -std=c++2a
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
2023-10-02 1:16 ` [Bug c++/111660] " envia at envia dot pe.kr
2023-10-02 1:17 ` envia at envia dot pe.kr
@ 2023-10-02 1:18 ` envia at envia dot pe.kr
2023-10-02 1:24 ` envia at envia dot pe.kr
` (12 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: envia at envia dot pe.kr @ 2023-10-02 1:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
--- Comment #3 from Hwang Joonhyung <envia at envia dot pe.kr> ---
Created attachment 56027
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56027&action=edit
It took 36 seconds.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] Compilation of constexpr function returning enum takes exponential time with -std=c++2a
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (2 preceding siblings ...)
2023-10-02 1:18 ` envia at envia dot pe.kr
@ 2023-10-02 1:24 ` envia at envia dot pe.kr
2023-10-02 1:26 ` pinskia at gcc dot gnu.org
` (11 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: envia at envia dot pe.kr @ 2023-10-02 1:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
--- Comment #4 from Hwang Joonhyung <envia at envia dot pe.kr> ---
I can see the time spent changes exponentially when I change the number of
ternary operators in the constexpr function.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] Compilation of constexpr function returning enum takes exponential time with -std=c++2a
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (3 preceding siblings ...)
2023-10-02 1:24 ` envia at envia dot pe.kr
@ 2023-10-02 1:26 ` pinskia at gcc dot gnu.org
2023-10-02 1:26 ` pinskia at gcc dot gnu.org
` (10 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-02 1:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note for non-C++11 constexpr, using switch here would most likely be better .
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] Compilation of constexpr function returning enum takes exponential time with -std=c++2a
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (4 preceding siblings ...)
2023-10-02 1:26 ` pinskia at gcc dot gnu.org
@ 2023-10-02 1:26 ` pinskia at gcc dot gnu.org
2023-10-02 1:31 ` pinskia at gcc dot gnu.org
` (9 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-02 1:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Hwang Joonhyung from comment #0)
> It took more than 30 minutes when I compiled testcase.cc with g++ 14.0.0
> 20231001 on Debian GNU/Linux 12 with -std=gnu++2a (or gnu++20, c++2a, c++20).
> I guess it is a regression because it finishes within 0.1 second with g++
> 13.2.0 or 12.3.0.
> The testcase is based on GetOneCharToken() of V8.
Does -fno-checking solve the performance issue?
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] Compilation of constexpr function returning enum takes exponential time with -std=c++2a
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (5 preceding siblings ...)
2023-10-02 1:26 ` pinskia at gcc dot gnu.org
@ 2023-10-02 1:31 ` pinskia at gcc dot gnu.org
2023-10-02 1:33 ` [Bug c++/111660] [14 Regression] " pinskia at gcc dot gnu.org
` (8 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-02 1:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
38.25% cc1plus cc1plus [.] walk_tree_1
34.60% cc1plus cc1plus [.] cp_fold_immediate_r
20.08% cc1plus cc1plus [.] cp_walk_subtrees
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] [14 Regression] Compilation of constexpr function returning enum takes exponential time with -std=c++2a
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (6 preceding siblings ...)
2023-10-02 1:31 ` pinskia at gcc dot gnu.org
@ 2023-10-02 1:33 ` pinskia at gcc dot gnu.org
2023-10-02 1:39 ` envia at envia dot pe.kr
` (7 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-02 1:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2023-10-02
Target Milestone|--- |14.0
Summary|Compilation of constexpr |[14 Regression] Compilation
|function returning enum |of constexpr function
|takes exponential time with |returning enum takes
|-std=c++2a |exponential time with
| |-std=c++2a
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I suspect r14-4140-g6851e3423c2b5e introduced the compile time slowness.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] [14 Regression] Compilation of constexpr function returning enum takes exponential time with -std=c++2a
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (7 preceding siblings ...)
2023-10-02 1:33 ` [Bug c++/111660] [14 Regression] " pinskia at gcc dot gnu.org
@ 2023-10-02 1:39 ` envia at envia dot pe.kr
2023-10-02 2:39 ` envia at envia dot pe.kr
` (6 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: envia at envia dot pe.kr @ 2023-10-02 1:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
--- Comment #9 from Hwang Joonhyung <envia at envia dot pe.kr> ---
(In reply to Andrew Pinski from comment #6)
> (In reply to Hwang Joonhyung from comment #0)
> > It took more than 30 minutes when I compiled testcase.cc with g++ 14.0.0
> > 20231001 on Debian GNU/Linux 12 with -std=gnu++2a (or gnu++20, c++2a, c++20).
> > I guess it is a regression because it finishes within 0.1 second with g++
> > 13.2.0 or 12.3.0.
> > The testcase is based on GetOneCharToken() of V8.
>
> Does -fno-checking solve the performance issue?
No. It took almost the same time. I used -std=gnu++2a -fno-checking.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] [14 Regression] Compilation of constexpr function returning enum takes exponential time with -std=c++2a
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (8 preceding siblings ...)
2023-10-02 1:39 ` envia at envia dot pe.kr
@ 2023-10-02 2:39 ` envia at envia dot pe.kr
2023-10-02 13:34 ` ppalka at gcc dot gnu.org
` (5 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: envia at envia dot pe.kr @ 2023-10-02 2:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
--- Comment #10 from Hwang Joonhyung <envia at envia dot pe.kr> ---
(In reply to Andrew Pinski from comment #5)
> Note for non-C++11 constexpr, using switch here would most likely be better .
Thank you for the comment. It helped me to solve my problem.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] [14 Regression] Compilation of constexpr function returning enum takes exponential time with -std=c++2a
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (9 preceding siblings ...)
2023-10-02 2:39 ` envia at envia dot pe.kr
@ 2023-10-02 13:34 ` ppalka at gcc dot gnu.org
2023-10-02 14:43 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-10-02 13:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org,
| |ppalka at gcc dot gnu.org
--- Comment #11 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #8)
> I suspect r14-4140-g6851e3423c2b5e introduced the compile time slowness.
Confirmed.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] [14 Regression] Compilation of constexpr function returning enum takes exponential time with -std=c++2a
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (10 preceding siblings ...)
2023-10-02 13:34 ` ppalka at gcc dot gnu.org
@ 2023-10-02 14:43 ` mpolacek at gcc dot gnu.org
2023-10-04 9:41 ` [Bug c++/111660] [14 Regression] Compilation of constexpr function returning enum takes exponential time with -std=c++2a since r14-4140-g6851e3423c2b5e rguenth at gcc dot gnu.org
` (3 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-10-02 14:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] [14 Regression] Compilation of constexpr function returning enum takes exponential time with -std=c++2a since r14-4140-g6851e3423c2b5e
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (11 preceding siblings ...)
2023-10-02 14:43 ` mpolacek at gcc dot gnu.org
@ 2023-10-04 9:41 ` rguenth at gcc dot gnu.org
2023-10-12 19:17 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-04 9:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P1
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] [14 Regression] Compilation of constexpr function returning enum takes exponential time with -std=c++2a since r14-4140-g6851e3423c2b5e
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (12 preceding siblings ...)
2023-10-04 9:41 ` [Bug c++/111660] [14 Regression] Compilation of constexpr function returning enum takes exponential time with -std=c++2a since r14-4140-g6851e3423c2b5e rguenth at gcc dot gnu.org
@ 2023-10-12 19:17 ` mpolacek at gcc dot gnu.org
2023-10-17 21:42 ` cvs-commit at gcc dot gnu.org
2023-10-17 21:43 ` mpolacek at gcc dot gnu.org
15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-10-12 19:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
--- Comment #12 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Candidate fix:
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -1072,7 +1072,7 @@ cp_fold_immediate_r (tree *stmt_p, int *walk_subtrees,
void *data_)
/* We're done here. Don't clear *walk_subtrees here though: we're
called
from cp_fold_r and we must let it recurse on the expression with
cp_fold. */
- break;
+ return integer_zero_node;
case PTRMEM_CST:
if (TREE_CODE (PTRMEM_CST_MEMBER (stmt)) == FUNCTION_DECL
&& DECL_IMMEDIATE_FUNCTION_P (PTRMEM_CST_MEMBER (stmt)))
@@ -1145,7 +1145,8 @@ cp_fold_immediate (tree *tp, mce_value
manifestly_const_eval)
flags |= ff_mce_false;
cp_fold_data data (flags);
- return !!cp_walk_tree_without_duplicates (tp, cp_fold_immediate_r, &data);
+ tree r = cp_walk_tree_without_duplicates (tp, cp_fold_immediate_r, &data);
+ return r == error_mark_node;
}
/* Perform any pre-gimplification folding of C++ front end trees to
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] [14 Regression] Compilation of constexpr function returning enum takes exponential time with -std=c++2a since r14-4140-g6851e3423c2b5e
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (13 preceding siblings ...)
2023-10-12 19:17 ` mpolacek at gcc dot gnu.org
@ 2023-10-17 21:42 ` cvs-commit at gcc dot gnu.org
2023-10-17 21:43 ` mpolacek at gcc dot gnu.org
15 siblings, 0 replies; 17+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-17 21:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
--- Comment #13 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:765c3b8f82d50961008c214ac2113f35e7532aa9
commit r14-4693-g765c3b8f82d50961008c214ac2113f35e7532aa9
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Oct 12 15:58:05 2023 -0400
c++: Fix compile-time-hog in cp_fold_immediate_r [PR111660]
My recent patch introducing cp_fold_immediate_r caused exponential
compile time with nested COND_EXPRs. The problem is that the COND_EXPR
case recursively walks the arms of a COND_EXPR, but after processing
both arms it doesn't end the walk; it proceeds to walk the
sub-expressions of the outermost COND_EXPR, triggering again walking
the arms of the nested COND_EXPR, and so on. This patch brings the
compile time down to about 0m0.030s.
The ff_fold_immediate flag is unused after this patch but since I'm
using it in the P2564 patch, I'm not removing it now. Maybe at_eof
can be used instead and then we can remove ff_fold_immediate.
PR c++/111660
gcc/cp/ChangeLog:
* cp-gimplify.cc (cp_fold_immediate_r) <case COND_EXPR>: Don't
handle it here.
(cp_fold_r): Handle COND_EXPR here.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/hog1.C: New test.
* g++.dg/cpp2a/consteval36.C: New test.
^ permalink raw reply [flat|nested] 17+ messages in thread
* [Bug c++/111660] [14 Regression] Compilation of constexpr function returning enum takes exponential time with -std=c++2a since r14-4140-g6851e3423c2b5e
2023-10-02 1:14 [Bug c++/111660] New: Compilation of constexpr function returning enum takes exponential time with -std=c++2a envia at envia dot pe.kr
` (14 preceding siblings ...)
2023-10-17 21:42 ` cvs-commit at gcc dot gnu.org
@ 2023-10-17 21:43 ` mpolacek at gcc dot gnu.org
15 siblings, 0 replies; 17+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-10-17 21:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111660
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #14 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 17+ messages in thread