[llvm-dev] Ineffective code after loop unrolling with -O3, ok with -Os

Dávid Bolvanský via llvm-dev llvm-dev at lists.llvm.org
Tue Apr 3 09:15:15 PDT 2018


Hi all,

I found some issues during my testing of "loop unrolling" capabilities of
LLVM's opt.

Seems like LLVM generates slower code with -O3 since it wrongly decides to
unroll a simple loop.
With option -Os, no loop unrolling, the output looks well.

Code:
https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,lang:c%2B%2B,source:'%23include+%3Ccstdio%3E%0A%0Aint+f(void)%0A%7B%0A++int+n+%3D+100%3B%0A++while+(--n)+%7B%0A++++++puts(%22a%22)%3B%0A++%7D%0A++return+0%3B%0A%7D%0A%0Aint+main(void)+%7B%0A++++f()%3B%0A++++return+0%3B%0A%7D'),l:'5
',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:33.61947345592715,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:g73,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'0'),lang:c%2B%2B,libs:!(),options:'-O3',source:1),l:'5',n:'0',o:'x86-64+gcc+7.3+(Editor+%231,+Compiler+%231)+C%2B%2B',t:'0')),header:(),k:33.04719321073953,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang600,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'0'),lang:c%2B%2B,libs:!(),options:'-O3',source:1),l:'5',n:'0',o:'x86-64+clang+6.0.0+(Editor+%231,+Compiler+%232)+C%2B%2B',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180403/4eacc7c9/attachment.html>


More information about the llvm-dev mailing list