Looking at the disassembly of a C++ program, I see functions like _Z41__static_initialization_and_destruction_0ii.constprop.221
. What does the constprop
mean in this case? It appears to be similar in appearance to the isra suffix (and is sometimes combined, e.g. .isra.124.constprop.226
), but it means something else.
Asked
Active
Viewed 1.0k times
19
1 Answers
8
From source code comments I've read - they indicate functions which have been cloned during optimization.
EDIT: This may be the answer, maybe not.
Simple constant propagation
This file implements constant propagation and merging. It looks for instructions involving only constant operands and replaces them with a constant value instead of an instruction. For example:
add i32 1, 2
becomes
i32 3
NOTE: this pass has a habit of making definitions be dead. It is a good idea to to run a DIE (Dead Instruction Elimination) pass sometime after running this pass.
-
Do you happen to know what optimization is being performed? – nneonneo Feb 13 '13 at 23:59
-
1Cool. It looks like it might be interprocedure constant propagation since it creates multiple versions of the functions. Though the document is for LLVM, I guess a similar thing must apply to GCC. – nneonneo Feb 14 '13 at 14:03
-
6Always fun to resurrect an old thread. :) I'm not a gcc dev, but I will add a few things to this. If you have a static function and you happen to call it with a certain constant (or constants) for one or some of its parameter(s), gcc can create an optimized version just for that combination of parameter value(s). This phenomena can be exploited in very interesting ways. – Daniel Santos Jul 01 '14 at 07:54
-
2@DanielSantos Thanks, this helped me figure out why my `always_inline` function was not inlined, but `call`-ed. – yyny Oct 26 '16 at 21:00
-
2@YoYoYonnY Depending upon what you're trying to do, this can be a problem and is the reason the `flatten` function attribute was added. If you defined the *calling* function with this attribute, it should force the inlining (of everything that it can). I *think* that the reason it isn't doing it is because the compiler thinks that the constant-propagated version is better. I had this discussion with a gcc dev some time back, but I can't remember all of the nuances. – Daniel Santos Dec 04 '16 at 21:00