public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/35305] New: Speculative PRE support missing
@ 2008-02-23 5:15 xinliangli at gmail dot com
2008-05-03 0:35 ` [Bug middle-end/35305] " pinskia at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: xinliangli at gmail dot com @ 2008-02-23 5:15 UTC (permalink / raw)
To: gcc-bugs
// File this bug to track the problem
int g1, g2;
void foo(int a, int b, int k,int m)
{
if (k)
{
#pragma execution_frequency(very_high)
g1 = a + b;
}
if (m)
{
#pragma execution_frequency(very_high)
g2 = a + b;
}
}
--
Summary: Speculative PRE support missing
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: xinliangli at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35305
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <bug-35305-4@http.gcc.gnu.org/bugzilla/>]
* [Bug middle-end/35305] Speculative PRE support missing
[not found] <bug-35305-4@http.gcc.gnu.org/bugzilla/>
@ 2012-10-30 18:58 ` xinliangli at gmail dot com
0 siblings, 0 replies; 6+ messages in thread
From: xinliangli at gmail dot com @ 2012-10-30 18:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35305
--- Comment #4 from davidxl <xinliangli at gmail dot com> 2012-10-30 18:57:18 UTC ---
The suggested transformation can be useful in some cases, but won't be general
enough. The listed example is an extreme case. For instance, the second a+b
instance does not have to be in the hot trace but still still hot enough to be
PREed. Or there is no one dominating traces available -- the expression is
available in all incoming paths except for one rare path.
switch (a)
{
case 1:
g[1] = a + b;
break;
case 2:
g[2] = a + b;
break;
case 3:
g[3] = a + b;
...
default:
g[0] = 0;
}
switch (b)
{
case 1:
... a + b; // partially redundant
case 2:
... a + b; // redundant
default:
// does nothing
break;
}
Regarding handling dereferences, the availability and down-safety analysis
needs to be extended to to recognize safe speculation candidates.
Example 1: dereference of same pointer fully available --
int g1, g2;
struct A
{
int a;
int b;
};
void foo(struct A* ap, int k,int m)
{
if (__builtin_expect (k, 1))
g1 = ap->b;
else
g2 = ap->a;
if (__builtin_expect (m, 1))
{
g2 = ap->b; // Good safe speculative PRE candidate
}
}
Example 2: deference of ap fully anticipated
int g1, g2;
struct A
{
int a;
int b;
};
void foo(struct A* ap, int k,int m)
{
if (__builtin_expect (k, 1))
g1 = ap->b;
if (__builtin_expect (m, 1))
g2 = ap->b; // Safe to speculatively hoist across the branch
into the else of the previous branch
else
g1 = ap->a;
}
David
(In reply to comment #3)
> Wouldn't this be a candidate for forming a superblock from hot traces of
> a function? Thus in the testcase
>
> if (k && m)
> {
> g1 = a + b;
> g2 = a + b;
> }
> else
> {
> ... old code
> }
>
> which would also handle the case where we cannot speculatively move code
> (like dereferences)?
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-10-30 18:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-23 5:15 [Bug middle-end/35305] New: Speculative PRE support missing xinliangli at gmail dot com
2008-05-03 0:35 ` [Bug middle-end/35305] " pinskia at gcc dot gnu dot org
2009-02-06 21:53 ` steven at gcc dot gnu dot org
2009-03-21 0:54 ` steven at gcc dot gnu dot org
2009-03-21 10:53 ` rguenth at gcc dot gnu dot org
[not found] <bug-35305-4@http.gcc.gnu.org/bugzilla/>
2012-10-30 18:58 ` xinliangli at gmail dot com
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).