<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">It seems to me that you're not running any LLVM IR optimization passes before JIT'ing the code.<div><br></div><div>In my code, I have:</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span class="Apple-style-span" style="color: rgb(79, 129, 135); "><span style="color: #733ba7">PassManager</span><span style="color: #000000">*<span class="Apple-tab-span" style="white-space:pre">          </span></span>m_PassManager;</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span class="Apple-style-span" style="color: rgb(79, 129, 135); "></span>// Adds the same module passes as -O3. Copied from opt.cpp in the</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); ">// llc - llvm compiler codeline.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(65, 27, 127); "><span style="color: #733ba7">Pass</span><span style="color: #000000"> *inliningPass = </span>createFunctionInliningPass<span style="color: #000000">();</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(65, 27, 127); ">createStandardModulePasses<span style="color: #000000">(<span class="Apple-tab-span" style="white-space:pre">    </span>m_PassManager, </span><span style="color: #3527d4">3</span><span style="color: #000000">,</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">                           </span></span>/*OptimizeSize=*/<span style="color: #000000"> </span><span style="color: #bc24a0">false</span><span style="color: #000000"><span class="Apple-style-span" style="color: rgb(0, 133, 24); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">                                                                                </span></span>/*UnitAtATime=*/<span style="color: #000000"> </span><span style="color: #bc24a0">true</span><span style="color: #000000">,</span></span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">                          </span></span>/*UnrollLoops=*/<span style="color: #000000"> </span><span style="color: #bc24a0">true</span><span style="color: #000000">,</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">                            </span></span>/*SimplifyLibCalls=*/<span style="color: #000000"> </span><span style="color: #bc24a0">true</span><span style="color: #000000">,</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">                               </span></span>/*HaveExceptions=*/<span style="color: #000000"> </span><span style="color: #bc24a0">true</span><span style="color: #000000">,</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-tab-span" style="white-space:pre">                              </span>inliningPass );</div><div><font class="Apple-style-span" face="Menlo" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font></div><div>( the 3 is the optimization level) and then later:</div><div><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(0, 133, 24); ">// Run the optimization passes for the module.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">m_PassManager-><span style="color: #411b7f">run</span>( *m_Module );</div><div><br></div><div>I also optionally have a call to:</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(65, 27, 127); "><span style="color: #000000">m_PassManager-></span>add<span style="color: #000000">( </span>createPrintModulePass<span style="color: #000000">( &</span>dbgs<span style="color: #000000">() ) );</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(65, 27, 127); "><font class="Apple-style-span" color="#000000"><br></font></div></div><div>before this which outputs the pre-optimized code to the debug stream. I dump the module after running the optimization passes and it's pretty easy to see what changes have been made to the LLVM IR.  They are generally quite significant as the optimizer passes do some amazing things.</div><div><br></div><div><span class="Apple-style-span" style="color: rgb(65, 27, 127); font-family: Menlo; font-size: 11px; ">createStandardModulePasses</span></div><div><br></div><div>is the code used by llc to optimize the LLVM IR, so passing a 3 as the optimization level parameter is the equivalent to passsing -O3 to llc. It adds a ton of different optimization passes. You can find the code for it in the file opt.cpp.</div><div><br></div><div>- Curtis</div><div><br></div><div><br></div><div>n Jun 25, 2010, at 6:06 PM, Yuri wrote:</div><div><br class="Apple-interchange-newline"><blockquote type="cite"><div>I run large piece of code in JIT and it runs only marginallty faster <br>with optimization levels 1,2,3. I think differences are within the <br>margin or error.<br><br>level     user time<br>0           17339ms<br>1           16913ms<br>2           16891ms<br>3           16898ms<br><br>Level is set with builder->setOptLevel(olev);<br>Compilation time is excluded by taking the only top-level function <br>address before the run with getPointerToFunction. So I measure time <br>without getPointerToFunction.<br><br>Why optimization almost doesn't speed it up? What are the other than <br>setOptLevel ways to control optimization?<br><br>My mindset is defined by experience with gcc, when increasing inlining <br>levels speeds the code up significantly. Does JIT inline at all?<br>It's hard to believe that even only local (no inlining) optimization <br>wouldn't bring timing down by at least 10%.<br><br>i386 on i7<br>r106715<br><br>Yuri<br>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></div></blockquote></div><br></div></body></html>