What can I expect from a compiler to be able to embed it?

Are there any general rules that I can use to evaluate whether a modern compiler will be embedded in a function? What is the relative cost of the extra stack frame (I know that it is very small, but is there any way to quantify it β€” about an order of magnitude)?

I am also particularly interested in:

  • Is it possible to use built-in compiler methods in cpp?
  • I know that some compilers implement some optimizations even in debugging (VS uses RVO in debugging, but not NRVO). What is the situation for inline? I would suggest that it is disabled so that we can see the expected call stack for debugging.

I'm currently trying to optimize a memory tracking system, especially those that are also applied without optimization (in debugging).

+1
source share
1 answer

Easy to predict and hard to predict. Simple expressions, for example:

int a = b + (2 * c): int d = e + (2 * c); 

optimized with the simplest optimizations (total subexpression (2 * c) "will be calculated only once.

In C / C ++, methods declared in general will (though not always).

Trickier is loop optimization, etc. For instance,

 for (int i = 1; i < n; i++) { a = i + (2 * c); } 

expression (2 * c) usually pulled out of a loop, in a compiler that performs "global optimization", but not in one that performs only "local optimization". And, of course, expressions can be much more complicated and confusing.

Change the body of the above loop to a = i * (2 * c); and you’re moving to a slightly higher level of global optimization, known as loop induction. The smart compiler will only expect to add 2 * c (as previously calculated) to a for each iteration through the loop, instead of doing (more expensive) multiplication at each iteration.

And it just scratches the surface.

But I have no idea what Visual Studio compilers are capable of.

+2
source

Source: https://habr.com/ru/post/909687/


All Articles