public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95481] New: Failure to optimize infinite recursion for struct types
@ 2020-06-02 16:55 gabravier at gmail dot com
2020-06-02 17:07 ` [Bug middle-end/95481] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: gabravier at gmail dot com @ 2020-06-02 16:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95481
Bug ID: 95481
Summary: Failure to optimize infinite recursion for struct
types
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
struct A {};
struct A foo()
{
return foo();
}
This can be optimized to an infinite loop. With -O3, GCC currently outputs an
explicit recursive call like this :
foo():
sub rsp, 8
call foo()
xor eax, eax
add rsp, 8
ret
When it could just do this :
foo():
.L2:
jmp .L2
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/95481] Failure to optimize infinite recursion for struct types
2020-06-02 16:55 [Bug tree-optimization/95481] New: Failure to optimize infinite recursion for struct types gabravier at gmail dot com
@ 2020-06-02 17:07 ` pinskia at gcc dot gnu.org
2021-05-30 22:45 ` [Bug tree-optimization/95481] Failure to optimize infinite recursion for empty " pinskia at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-06-02 17:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95481
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/95481] Failure to optimize infinite recursion for empty struct types
2020-06-02 16:55 [Bug tree-optimization/95481] New: Failure to optimize infinite recursion for struct types gabravier at gmail dot com
2020-06-02 17:07 ` [Bug middle-end/95481] " pinskia at gcc dot gnu.org
@ 2021-05-30 22:45 ` pinskia at gcc dot gnu.org
2021-05-31 0:21 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-05-30 22:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95481
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|middle-end |tree-optimization
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2021-05-30
Summary|Failure to optimize |Failure to optimize
|infinite recursion for |infinite recursion for
|struct types |empty struct types
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The problem only exist for empty structs. If we add a field, we get the better
code:
foo:
.LFB0:
.cfi_startproc
.p2align 3,,7
.L2:
b .L2
The reason why this happens is because we remove the assignment for empty
struct assignment during gimplification. This messes up how tailr and tailc
works.
Note here is a testcase for tailc:
struct A {};
struct A goo(void);
struct A foo(void)
{
return goo();
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/95481] Failure to optimize infinite recursion for empty struct types
2020-06-02 16:55 [Bug tree-optimization/95481] New: Failure to optimize infinite recursion for struct types gabravier at gmail dot com
2020-06-02 17:07 ` [Bug middle-end/95481] " pinskia at gcc dot gnu.org
2021-05-30 22:45 ` [Bug tree-optimization/95481] Failure to optimize infinite recursion for empty " pinskia at gcc dot gnu.org
@ 2021-05-31 0:21 ` pinskia at gcc dot gnu.org
2021-05-31 6:32 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-05-31 0:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95481
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 50892
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50892&action=edit
Patch which I am testing
I need to change the comment before the if statement and add a few testcases.
But this is the patch which I am testing which fixes the problem.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/95481] Failure to optimize infinite recursion for empty struct types
2020-06-02 16:55 [Bug tree-optimization/95481] New: Failure to optimize infinite recursion for struct types gabravier at gmail dot com
` (2 preceding siblings ...)
2021-05-31 0:21 ` pinskia at gcc dot gnu.org
@ 2021-05-31 6:32 ` pinskia at gcc dot gnu.org
2021-06-01 18:29 ` cvs-commit at gcc dot gnu.org
2021-06-01 18:31 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-05-31 6:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95481
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
URL| |https://gcc.gnu.org/piperma
| |il/gcc-patches/2021-May/571
| |490.html
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch submitted
https://gcc.gnu.org/pipermail/gcc-patches/2021-May/571490.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/95481] Failure to optimize infinite recursion for empty struct types
2020-06-02 16:55 [Bug tree-optimization/95481] New: Failure to optimize infinite recursion for struct types gabravier at gmail dot com
` (3 preceding siblings ...)
2021-05-31 6:32 ` pinskia at gcc dot gnu.org
@ 2021-06-01 18:29 ` cvs-commit at gcc dot gnu.org
2021-06-01 18:31 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-01 18:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95481
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:
https://gcc.gnu.org/g:ea418485c700494c3efdc282854c5f5a08702416
commit r12-1151-gea418485c700494c3efdc282854c5f5a08702416
Author: Andrew Pinski <apinski@marvell.com>
Date: Mon May 31 00:17:22 2021 +0000
Fix PR 95481: tail call fails with empty struct types
The problem here is we don't have an assignment type any more
for empty structs as they were removed during gimplifcation.
This adds a special case where the assignment var does not exist
and the return decl is empty typed.
OK? Tested on aarch64-linux-gnu with no regressions.
Thanks,
Andrew Pinski
changes since v1:
v2: Use is_empty_type instead of zero-sized type.
gcc/ChangeLog:
PR tree-optimization/95481
* tree-tailcall.c (find_tail_calls): Handle empty typed
return decls.
gcc/testsuite/ChangeLog:
PR tree-optimization/95481
* gcc.dg/tree-ssa/tailcall-10.c: New test.
* gcc.dg/tree-ssa/tailcall-11.c: New test.
* gcc.dg/tree-ssa/tailcall-12.c: New test.
* gcc.dg/tree-ssa/tailcall-13.c: New test.
* gcc.dg/tree-ssa/tailrecursion-8.c: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/95481] Failure to optimize infinite recursion for empty struct types
2020-06-02 16:55 [Bug tree-optimization/95481] New: Failure to optimize infinite recursion for struct types gabravier at gmail dot com
` (4 preceding siblings ...)
2021-06-01 18:29 ` cvs-commit at gcc dot gnu.org
@ 2021-06-01 18:31 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-01 18:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95481
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
Target Milestone|--- |12.0
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-06-01 18:31 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02 16:55 [Bug tree-optimization/95481] New: Failure to optimize infinite recursion for struct types gabravier at gmail dot com
2020-06-02 17:07 ` [Bug middle-end/95481] " pinskia at gcc dot gnu.org
2021-05-30 22:45 ` [Bug tree-optimization/95481] Failure to optimize infinite recursion for empty " pinskia at gcc dot gnu.org
2021-05-31 0:21 ` pinskia at gcc dot gnu.org
2021-05-31 6:32 ` pinskia at gcc dot gnu.org
2021-06-01 18:29 ` cvs-commit at gcc dot gnu.org
2021-06-01 18:31 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).