public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/98292] New: Optimize away C return; in function returning integral/pointer
@ 2020-12-15 16:29 jakub at gcc dot gnu.org
2021-01-06 12:01 ` [Bug tree-optimization/98292] " marxin at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-12-15 16:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98292
Bug ID: 98292
Summary: Optimize away C return; in function returning
integral/pointer
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: jakub at gcc dot gnu.org
Target Milestone: ---
This is related to the PR94779, but that one talks just about switches.
int
foo (int x)
{
if (x > 20)
return x;
}
int
bar (int x)
{
if (x > 30)
return 30;
}
int
baz (int x)
{
if (x > 40)
return x + 1U;
}
int
qux (int x)
{
if (x > 50)
return x | 32;
}
is optimized to just the return statement in C++ (because we add
__builtin_unreachable() in that case), but not in C.
I think we should do that also in C, provided that there are no non-debug
non-CLOBBER stmts on the branch with GIMPLE_RETURN without argument, and
provided that on the other branch there are just very few cheap stmts
guaranteed not to invoke UB/trap (appart from debug/CLOBBER stmts) plus the
GIMPLE_RETURN with argument.
LLVM seems to optimize that (though not sure if it isn't because it incorrectly
adds something like __builtin_unreachable () even for C).
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/98292] Optimize away C return; in function returning integral/pointer
2020-12-15 16:29 [Bug tree-optimization/98292] New: Optimize away C return; in function returning integral/pointer jakub at gcc dot gnu.org
@ 2021-01-06 12:01 ` marxin at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-01-06 12:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98292
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2021-01-06
Status|UNCONFIRMED |NEW
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
I have one more idea. We've been building openSUSE distribution with
-Werror=return-type for quite some time.
Would it be possible to add a new option for C that will enforce that same
behavior? By doing that, we can benefit for free.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-01-06 12:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-15 16:29 [Bug tree-optimization/98292] New: Optimize away C return; in function returning integral/pointer jakub at gcc dot gnu.org
2021-01-06 12:01 ` [Bug tree-optimization/98292] " marxin 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).