Influencing function cloning/duplication/constant propagation in gcc

牧云@^-^@ 提交于 2019-12-05 08:48:06

What matters is whether the function is called with a constant argument (either an actual constant expression, or something determined to be constant by the compiler via constant propagation). In this case, GCC will clone the function unless it determines doing so would be too costly or have too little benefit; I don't know a way to influence that metric. Be aware that constant propagation happens only within a single translation unit (source file) unless you're compiling the whole program at once or using link-time optimization, and I'm not sure whether cloning can still happen at that point or not.

My best guess, if cloning isn't happening when you expect that it should, is that GCC is never seeing a constant argument where the function is called. Even if you know it will be constant, the compiler might not be able to prove it is.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!