<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Adding CC: cfe-dev <div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 2, 2015, at 9:56 AM, Phil Tomson via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">
<span style="" title="View upvote and downvote totals" itemprop="upvoteCount" class="">0</span>
<a class="" title="This question does not show any research effort; it is unclear or not useful">down vote</a>
<a class="" href="http://stackoverflow.com/questions/34049511/how-to-pass-optimization-passes-to-clang#" title="This is a favorite question (click again to undo)">favorite</a>
</div>
<div class="">
<div class="" itemprop="text"><p class="">I'm trying to debug an issue for a new target where a testcase fails with -O1 optimization and passes with -O0 optimization. </p><p class="">I got a list of optimization passes being performed when 'clang -O1' is called like this:</p>
<pre class=""><code class="">llvm-as < /dev/null | opt -O1 -disable-output -debug-pass=Arguments
</code></pre><p class="">Which results in:</p><p class="">Pass Arguments: -no-aa -tbaa -targetlibinfo -basicaa -notti -preverify -domtree -verify -simplifycfg -domtree -sroa -early-cse -lower-expect<br class="">Pass Arguments: -targetlibinfo -no-aa -tbaa -basicaa -notti -globalopt -ipsccp -deadargelim -instcombine -simplifycfg -basiccg -prune-eh -inline-cost -always-inline -functionattrs -sroa -domtree -early-cse -simplify-libcalls -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -instcombine -tailcallelim -simplifycfg -reassociate -domtree -loops -loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -indvars -loop-idiom -loop-deletion -loop-unroll -memdep -memcpyopt -sccp -instcombine -lazy-value-info -jump-threading -correlated-propagation -domtree -memdep -dse -adce -simplifycfg -instcombine -strip-dead-prototypes -preverify -domtree -verify<br class=""></p><p class="">(BTW: why are there two Pass Arguments lists returned there?)<br class=""></p></div></div></div></div></blockquote><div>This is because the middle-end and the backend are using a different PassManager (I don’t think there is any reason for doing this but that’s how it’s implemented in clang).</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class="" itemprop="text"><p class="">Now my intent is to figure out which optimization pass is causing the
problem by trying each one until I hit the same problem as with -O1, but clang itself doesn't seem to allow these commandline
options, for example:</p>
<pre class=""><code class="">clang -loops -lcssa ....
</code></pre><p class="">Results in:</p>
<pre class=""><code class="">clang: warning: -loops: 'linker' input unused
clang: warning: -lcssa: 'linker' input unused<br class=""><br class=""></code></pre><pre class=""><code class=""><br class="">(Makes sense as it conflicts with the -l command line opt) <br class=""></code>So is there a way to pass these in on the command line? (or bonus if
there's a way to specify a file which contains a list of optimization
passes to perform)
</pre><p class="">Note: I realize there must be a way to break everything up into stages and use <em class="">opt</em>
at some point and pass the optimization command line options to it, but
I've got a pretty large set of Makefiles which would need to change to
do that.</p><div class=""><br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>There is no way that I know of (but modifying the PassManagerBuilder and rebuilding clang). But you may start by bisecting the input files compiling half of them with O1 and the other half with O0 and recurse till you find the file that is miscompiled with O1. Then you can use opt to test variant of the pipeline on this file and relink manually.</div><div><br class=""></div><div>— </div><div>Mehdi</div></div></div></body></html>