public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/65412] New: missing control flow optimisation
@ 2015-03-12 21:33 skvadrik at gmail dot com
2015-03-13 9:22 ` [Bug tree-optimization/65412] " rguenth at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: skvadrik at gmail dot com @ 2015-03-12 21:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65412
Bug ID: 65412
Summary: missing control flow optimisation
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: skvadrik at gmail dot com
Created attachment 35023
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35023&action=edit
files 1.c (source), 1.s (gcc assembly), 2.s (clang assembly)
Consider the following code:
void f(int x)
{
if (x == 0) f0();
else if (x == 1) f1();
else if (x == 2) f2();
else if (x == 3) f3();
else if (x == 4) f4();
else if (x == 5) f5();
}
gcc-4.9.2 doesn't optimize ifs to decision tree, jump table or something (see
1.s in attach). clang does (2.s in attach, jump table).
Maybe you could improve that?
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/65412] missing control flow optimisation
2015-03-12 21:33 [Bug tree-optimization/65412] New: missing control flow optimisation skvadrik at gmail dot com
@ 2015-03-13 9:22 ` rguenth at gcc dot gnu.org
2021-06-04 21:38 ` [Bug tree-optimization/65412] sequence of ifs not turned into a switch statement pinskia at gcc dot gnu.org
2021-06-04 21:41 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-03-13 9:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65412
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think there exist patches for if-to-switch conversion.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/65412] sequence of ifs not turned into a switch statement
2015-03-12 21:33 [Bug tree-optimization/65412] New: missing control flow optimisation skvadrik at gmail dot com
2015-03-13 9:22 ` [Bug tree-optimization/65412] " rguenth at gcc dot gnu.org
@ 2021-06-04 21:38 ` pinskia at gcc dot gnu.org
2021-06-04 21:41 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-04 21:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65412
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |10.0
Last reconfirmed|2015-12-28 00:00:00 |2021-6-4
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>From *.iftoswitch on the trunk:
;; Canonical GIMPLE case clusters: 0 1 2 3 4 5
So I looked and this is fixed but not for the low if count.
Take:
#define B(y) void f##y(void);
#define B10(y) B(y##0) B(y##1) B(y##2) \
B(y##3) B(y##4) B(y##5) \
B(y##6) B(y##7) B(y##8) \
B(y##9)
#define B100(y) B10(y##0) B10(y##1) B10(y##2) \
B10(y##3) B10(y##4) B10(y##5) \
B10(y##6) B10(y##7) B10(y##8) \
B10(y##9)
B10(1)
B100(1)
#define A(y) else if (x == y) f##y();
#define A10(y) A(y##0) \
A(y##1) \
A(y##2) \
A(y##3) \
A(y##4) \
A(y##5) \
A(y##6) \
A(y##7) \
A(y##8) \
A(y##9)
#define A100(y) A10(y##0) \
A10(y##1) \
A10(y##2) \
A10(y##3) \
A10(y##4) \
A10(y##5) \
A10(y##6) \
A10(y##7) \
A10(y##8) \
A10(y##9)
void f10(int x)
{
if (0) ;
A10(1)
}
void f100(int x)
{
if (0) ;
A100(1)
}
--- CUT ----
f100 is converted while f10 is not. This is a heuristics at work to see if it
is better as a jump table vs if statements.
https://godbolt.org/z/ofWGb5aKn for reference.
Clang decides (I don't know if they lower switches back to if statements) to do
the switch for all cases.
So we can close this as fixed.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/65412] sequence of ifs not turned into a switch statement
2015-03-12 21:33 [Bug tree-optimization/65412] New: missing control flow optimisation skvadrik at gmail dot com
2015-03-13 9:22 ` [Bug tree-optimization/65412] " rguenth at gcc dot gnu.org
2021-06-04 21:38 ` [Bug tree-optimization/65412] sequence of ifs not turned into a switch statement pinskia at gcc dot gnu.org
@ 2021-06-04 21:41 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-04 21:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65412
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang decides at 4 to change it to a switch statement while GCC takes a few
extra ifs to change it. Again this is heuristics at work.
#define B(y) void f##y(void);
#define B10(y) B(y##0) B(y##1) B(y##2) \
B(y##3) B(y##4) B(y##5) \
B(y##6) B(y##7) B(y##8) \
B(y##9)
B10(1)
#define A(y) else if (x == y) f##y();
void f10(int x)
{
if (0) ;
A(11)
A(12)
A(13)
A(14)
}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-06-04 21:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-12 21:33 [Bug tree-optimization/65412] New: missing control flow optimisation skvadrik at gmail dot com
2015-03-13 9:22 ` [Bug tree-optimization/65412] " rguenth at gcc dot gnu.org
2021-06-04 21:38 ` [Bug tree-optimization/65412] sequence of ifs not turned into a switch statement pinskia at gcc dot gnu.org
2021-06-04 21:41 ` 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).