This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Inlining functions vs. inlining member functions as templates


Hi Peter,

>Why doesn't the compiler manage to do the same thing for the function version, that it apparently does between -O1 and -O3 for the struct version?

It's a pretty tall order.  You are saying "Ignore what I explicitly programmed the function to do, and inline what I specified as a function pointer parameter because it will be more efficient".

Note:  a function pointer parameter is *NOT* the same as being able to inline an inline-tagged function.

>Or is it simply not allowed to do that kind of optimization for functions (i.e. function pointers)?

I believe there are two schools of thought.

School A:  C (and by extension, C++) is a really nice macro assemblers that have wonderful optimization techniques.  But I don't expect the compiler to do anything other than what I tell it to do.

School B:  as long as the programs output (including side-effects) is the same after some seriously impressive wholistic optimizations, I expect aggressive optimizing.  (Even if that makes the million function program turn into as-if it were all coded inside one gigantic main() routine -- if that's more efficient.)

I find that School A is the kind of optimization that I expect out of a C/C++ optimizing compiler.  Since I come from an assembly language (6502, 680x0) background, I think of C as a really neat macro assembler.  (But I think of C++ as an object oriented language moreso than a excellent macro assembler; go figure.)

And that School B is the kind of optimization that I expect out of a Java compiler *AND* a continuously optimizing/re-optimizing JIT JVM.

You can get some of the School B benefits in School A, if you have a feedback mechanism in your development process to feed profiling information back into the compilation process.  (Or if your C/C++ code (or tokenized binary thereof) was interpreted live instead of compiled.)  But even then, I really wouldn't expect* the compiler to ignore what you told it to do because some impressive wholistic optimization analysis technique.

* Not that it's impossible; just not what I'd expect.  I'd be pleasantly surprised if it did the kind of optimization that even changes function signatures to remove (optimize away) parameters (such as the function pointer parameter specified in your example)!  Wow!

Sincerely,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]