compiler-optimization

What compilers can inline indirect function calls?

The LDC D compiler for LLVM can inline indirect function calls under some circumstances if it can prove that the target is statically known. Here's a toy example (in D) of where this might happen: void main() { uint num; void incNum() { num++; } auto myDelegate = &incNum; myDelegate(); } In this case, ev...

How does O=Deparse work, and does Perl have and fold constant arrays?

I'm wondering, does -MO=Deparse show you all of the Perl optimizations, and why doesn't this get folded in Perl 5.10? $ perl -MO=Deparse -e'[qw/foo bar baz/]->[0]' ['foo', 'bar', 'baz']->[0]; -e syntax OK Some on IRC thought that O=Deparse might not be showing it all, but it certainly shows some constant folding. $ perl -MO=Deparse -...

What's the state of compilers that generate X86 assembly today?

Whenever I talk to people that work with real-time preformance they tend to point out that the generated X86 assembly instructions are not that efficent. With things like VMX on the horizon I have to ask, how likely is it that commercial C++ compilers will utilize these instruction sets? I get the feeling that compiler vendors don't emi...

VS2008 C++ Release mode slower than Debug mode

I am working with mixed Native and Managed Visual C++, using STL in the Native. I have a strange problem. It seems that when I compile my software in Release mode with all the optimizations set, my software consistently runs slower than in Debug mode. What could be wrong here? These are my Debug command line options: /Od /D "WIN32" /D ...

Examples of CLR compiler optimizations

I'm doing a presentation in few months about .Net performance and optimization, I wanted to provide some samples of unnecessary optimization, things that will be done by the compiler anyways. where can I find some explanation on what optimizations the compiler is actually capable of maybe some before and after code? ...

Visual Studio C++ compiler optimizations breaking code?

I've a peculiar issue here, which is happening both with VS2005 and 2010. I have a for loop in which an inline function is called, in essence something like this (C++, for illustrative purposes only): inline double f(int a) { if (a > 100) { // This is an error condition that shouldn't happen.. } // Do something with a and r...

Compiler code generation--register allocation inside conditional blocks.

I'm writing a compiler for a course. I've run into some optimization issues of which I am unsure how to handle optimally. Suppose there is a while loop from the input language that uses N local variables which must be held in registers (or should be, for fast computations). Suppose N > K, the number of registers. There is a chance of the...

In VC++ what is the #pragma equivalent of /O2 compiler option (optimize for speed)

According to msdn, /O2 (Maximize Speed) is equivalent to /Og/Oi/Ot/Oy/Ob2/Gs/GF/Gy and according to msdn again, the following pragma #pragma optimize( "[optimization-list]", {on | off} ) uses the same letters in its "optimization-list" than the /O compiler option. Available letters for the pragma are: g - Enable glob...

Why can't compiler optimize these 2 statements out?

Is there any reason that the compiler cannot optimize the following 2 statements out in main even I turned on fully optimization in Visual C++? Any side effect to access a int variable in memory? int _tmain(int argc, _TCHAR* argv[]) { volatile int pleaseOptimizeMeOut = 100; (pleaseOptimizeMeOut); return 0; } ...

How can I force the compiler-generated copy constructor of a class to *not* be inlined by the compiler?

Alternate question title would be: How to explicitly have the compiler generate code for the compiler-generated constructors in a specific translation unit? The problem we face is that for one code path the resulting -- thoroughly measured -- performance is better (by about 5%) if the copy-ctor calls of one object are not inlined, that ...

How do compilers optimize our code?

Hi, I ran into this question when i was answering another guys question. How do compilers optimize the code? Can keywords like const, ... help? Beside the fact with volatiles and inline functions and how to optimize the code all by your self! ...

In what cases does out-of-order execution result in more efficient code

I'm trying to understand how the Memory barrier works, why it is used and in what cases it should be used. However I'm not entirely sure in what cases it would be more efficient to arrange the order of instructions, can anyone give me an example of that? ...

What is my compiler doing? (optimizing memcpy)

I'm compiling a bit of code using the following settings in VC++2010: /O2 /Ob2 /Oi /Ot However I'm having some trouble understanding some parts of the assembly generated, I have put some questions in the code as comments. Also, what prefetching distance is generally recommended on modern cpus? I can ofc test on my own cpu, but I was h...

Unrolling gcc compiler optimization

I am interested in seeing the code where gcc has actually optimized the code. Is there a way I could do? I have gone through few other similar questoins, I have tried following few things, -Wa,ahl=filename.lst :- this option is really good, you can browse the code and corresponding machine code, but it is not good when I enable O3 opt...