public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/40175] New: emit optimzied versions of functions depending on constant argument(s)
@ 2009-05-17 11:46 thephilips at gmail dot com
2009-05-17 14:24 ` [Bug middle-end/40175] " pinskia at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: thephilips at gmail dot com @ 2009-05-17 11:46 UTC (permalink / raw)
To: gcc-bugs
An idea of semi-automatic optimization crossed my mind, which I could have
taken advantage on more than one project.
Imaging the code:
static int f1( int a, int b )
{
[... lots of computation using 'a', sometimes involving 'b' ...]
}
int main()
{
....
for (i=0; i<MAX; i++)
f1( arr[i], 0 );
...
for (i=0; i<MAX; i++)
f1( arr[i], 1 );
...
for (i=0; i<MAX; i++)
f1( arr[i], 2 );
...
}
Due to code size, inlining f1() is not always feasible.
Second parameter is always/mostly constant, yet it's evaluation inside f1()
cannot be optimized out without macro or inlining.
Idea I had was to allow some way for user to tell C/C++ that for particular
combinations of the function constant parameters, C/C++ needs to emit (and
optimize accordingly) a function specialization. Then all calls to the
function, which match some specialization should be replaced with the calls to
the corresponding function specialization.
E.g.:
static int f1( int a, int b )
{
[... lots of computation using 'a', sometimes involving 'b' ...]
}
static int f1( int a, int b ) __attribute__(( clone(b == 0), clone(b == 1),
clone( b == 2 ) ));
/* in total, four clones of f1() are emitted:
f1(var,var), f1(var,0), f1(var,1), f1(var,2) */
int main()
{
....
for (i=0; i<MAX; i++)
f1( arr[i], 0 ); /* would be replaced with call to specialization
with b == 0*/
...
for (i=0; i<MAX; i++)
f1( arr[i], 1 ); /* would be replaced with call to specialization
with b == 1 */
...
for (i=0; i<MAX; i++)
f1( arr[i], 2 ); /* would be replaced with call to specialization
with b == 2 */
...
}
I'm not sure whether that is possible to implement - or make sense at all. I'm
sure that would have helped me on many occasions in past when I had to
implement e.g. special check summing functions. Converting everything to macros
makes code only messier. Writing hand optimized versions for constant arguments
increases testing and maintenance overhead.
It would have been nice if GCC could help in the case.
--
Summary: emit optimzied versions of functions depending on
constant argument(s)
Product: gcc
Version: 4.3.4
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: thephilips at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40175
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug middle-end/40175] emit optimzied versions of functions depending on constant argument(s)
2009-05-17 11:46 [Bug c/40175] New: emit optimzied versions of functions depending on constant argument(s) thephilips at gmail dot com
@ 2009-05-17 14:24 ` pinskia at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-05-17 14:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2009-05-17 14:24 -------
-fipa-cp has been there since 4.1.0.
It is now enabled in 4.4.0 and above by default at -O2 and above (including
-Os).
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Component|c |middle-end
Resolution| |FIXED
Target Milestone|--- |4.1.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40175
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-05-17 14:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-17 11:46 [Bug c/40175] New: emit optimzied versions of functions depending on constant argument(s) thephilips at gmail dot com
2009-05-17 14:24 ` [Bug middle-end/40175] " pinskia at gcc dot gnu dot 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).