public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/55814] New: Missed optimization with short-circuit evaluation
@ 2012-12-26 17:45 tkoenig at gcc dot gnu.org
2012-12-26 21:46 ` [Bug middle-end/55814] Missed optimization with short-circuit evaluation of always evaluated comparisons/loads pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2012-12-26 17:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55814
Bug #: 55814
Summary: Missed optimization with short-circuit evaluation
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: middle-end
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: tkoenig@gcc.gnu.org
See PR 55806.
The Fortran front end generates code for intrinsics like ANY and ALL
which looks like (after loop unrolling)
_Bool foo(int *a, int *b)
{
_Bool f0, f1, f2, f3;
f0 = a[0] > b[0];
f1 = a[1] > b[1];
f2 = a[2] > b[2];
f3 = a[2] > b[2];
return f0 || f1 || f2 || f3;
}
There should be no need to perform the second comparison if the
first one is true.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/55814] Missed optimization with short-circuit evaluation of always evaluated comparisons/loads
2012-12-26 17:45 [Bug middle-end/55814] New: Missed optimization with short-circuit evaluation tkoenig at gcc dot gnu.org
@ 2012-12-26 21:46 ` pinskia at gcc dot gnu.org
2012-12-27 17:24 ` tkoenig at gcc dot gnu.org
2012-12-31 16:26 ` rguenth at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-12-26 21:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55814
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-12-26
Summary|Missed optimization with |Missed optimization with
|short-circuit evaluation |short-circuit evaluation of
| |always evaluated
| |comparisons/loads
Ever Confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-12-26 21:46:40 UTC ---
This is a sinking issue. Sinking of loads.
If the code was written as:
_Bool foo(int *a, int *b)
{
return (a[0] > b[0]) || (a[1] > b[1]) || (a[2] > b[2]) || (a[3] > b[3]);
}
Instead then it would short-circuit correctly.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/55814] Missed optimization with short-circuit evaluation of always evaluated comparisons/loads
2012-12-26 17:45 [Bug middle-end/55814] New: Missed optimization with short-circuit evaluation tkoenig at gcc dot gnu.org
2012-12-26 21:46 ` [Bug middle-end/55814] Missed optimization with short-circuit evaluation of always evaluated comparisons/loads pinskia at gcc dot gnu.org
@ 2012-12-27 17:24 ` tkoenig at gcc dot gnu.org
2012-12-31 16:26 ` rguenth at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2012-12-27 17:24 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55814
--- Comment #2 from Thomas Koenig <tkoenig at gcc dot gnu.org> 2012-12-27 17:23:54 UTC ---
An even more pronounced test case, where we could sink
a lot more stores, which in fact could lead to moving
a whole loop:
logical function bar(a,b,c)
logical, intent(in) :: a, b
logical, intent(in), dimension(3) :: c
bar = a .and. b .and. any(c)
end
This is translated by the Fortran FE to
bar (logical(kind=4) & restrict a, logical(kind=4) & restrict b,
logical(kind=4)[3] * restrict c)
{
logical(kind=4) __result_bar;
{
logical(kind=4) test.0;
test.0 = 0;
{
integer(kind=8) S.1;
S.1 = 1;
while (1)
{
if (S.1 > 3) goto L.2;
if (NON_LVALUE_EXPR <(*c)[S.1 + -1]>)
{
test.0 = 1;
goto L.1;
}
S.1 = S.1 + 1;
}
L.2:;
}
L.1:;
__result_bar = (*a && *b) && test.0;
}
return __result_bar;
}
which the middle-end then doesn't optimize - there would
be no need to evaluate the loop if either a or b were false.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/55814] Missed optimization with short-circuit evaluation of always evaluated comparisons/loads
2012-12-26 17:45 [Bug middle-end/55814] New: Missed optimization with short-circuit evaluation tkoenig at gcc dot gnu.org
2012-12-26 21:46 ` [Bug middle-end/55814] Missed optimization with short-circuit evaluation of always evaluated comparisons/loads pinskia at gcc dot gnu.org
2012-12-27 17:24 ` tkoenig at gcc dot gnu.org
@ 2012-12-31 16:26 ` rguenth at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-12-31 16:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55814
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> 2012-12-31 16:25:41 UTC ---
We do not sink loads aggressively.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-12-31 16:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-26 17:45 [Bug middle-end/55814] New: Missed optimization with short-circuit evaluation tkoenig at gcc dot gnu.org
2012-12-26 21:46 ` [Bug middle-end/55814] Missed optimization with short-circuit evaluation of always evaluated comparisons/loads pinskia at gcc dot gnu.org
2012-12-27 17:24 ` tkoenig at gcc dot gnu.org
2012-12-31 16:26 ` rguenth 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).