<div dir="ltr">+dehao.<div><br></div><div>There are two potential problems:</div><div><br></div><div>1) the branch gets eliminated in the binary that is being profiled, so there is no profile data</div><div>2) select instruction is lowered into branch -- but the branch profile data is not annotated back to the select instruction.</div><div><br></div><div>2) is something that can be improved in SampleFDO.<br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 12, 2016 at 10:06 AM, David Callahan via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">









<div style="word-wrap:break-word;color:rgb(0,0,0);font-size:14px;font-family:Calibri,sans-serif">
<div>
<p>I am looking for advice on a problem observed with<br>
-fprofile-sample-use for samples built with the AutoFDO tool<br>
<br>
I took the "hmmer" benchmark out of SPEC2006<br>
It is initially compiled<br>
<br>
   clnag++ -o hmmer -O3 -std=gnu89 -DSPEC_CPU -DNDEBUG -fno-strict-aliasing -w -g *.c<br>
<br>
This baseline binary runs in about 164.2 seconds as reported by "perf stat"<br>
<br>
We build a sample file from this program using the AutoFDO tool "create_llvm_prof"<br>
<br>
   perf report -b hmmer nph3.hmm swiss41wa<br></p></div></div></blockquote><div><br></div><div>perf record ?</div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;color:rgb(0,0,0);font-size:14px;font-family:Calibri,sans-serif"><div><p>
   create_llvm_prof -out hmmer.llvm ...<br>
<br>
and rebuild the binary using this profile<br>
<br>
   clnag++ -o hmmer-fdo -fprofile-sample-use=hmmer.<wbr>llvm \<br>
           -O3 -std=gnu89 -DSPEC_CPU -DNDEBUG -fno-strict-aliasing -w -g *.c<br>
<br>
now, sadly, this program runs in 231.2 seconds.<br>
<br>
The problem is that when a short conditional block is converted to a<br>
SelectInst, we are unable to accurately recover the branch frequencies<br>
since there is no actual branching. When we then compile in the<br>
presence of the sample, phase "CodeGen Prepare" examines the profile<br>
data and undoes the select conversion to disastrous results.<br>
<br></p></div></div></blockquote><div><br></div><div>This looks like a bug here -- is it likely that selectInst somehow gets annotated with bad profile data ? Should it make the same decision as if autoFDO is not used?</div><div><br></div><div>A smaller reproducible will be helpful here.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;color:rgb(0,0,0);font-size:14px;font-family:Calibri,sans-serif"><div><p>
If we compile -O0 for training, and then use the profile now with<br>
accurate branch weights, the program runs in 149.5<br>
seconds. Unfortunately, of course, the training program runs in 501.4<br>
seconds.<br>
<br>
Alternately, if we disable the original select conversion performed in<br>
SpeculativelyExecuteBB in SimplifyCFG.cpp so the original control is<br>
visible to sampling, the training program now runs in 229.7 seconds and<br>
the optimized program runs in 151.5, so we recover essentially all of<br>
lost information.<br>
<br>
Of course both if these options are unfortunate because they alter the<br>
workflow where it would be preferable to be able to monitor the<br>
production codes to feed back into production builds. That suggests<br>
that we remove the use of profile data in the CodeGen Prepare<br>
phase. When that change is made, and we sample the baseline -O3<br>
binary, the resulting optimized binary runs in 158.9 seconds.<br>
<br>
That result is at least slightly better than baseline instead of much<br>
worse but we are leaving 2-3% on the table. Maybe that is a reasonable<br>
trade-off for having only production builds.<br>
<br>
Any advice or suggestions?<br></p></div></div></blockquote><div><br></div><div>Please file a bug with something to reproduce : preprocessed file, compiler command line, and profile data in text form.</div><div><br></div><div>David</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;color:rgb(0,0,0);font-size:14px;font-family:Calibri,sans-serif"><div><p>
Thanks<span class="HOEnZb"><font color="#888888"><br>
david<u></u><u></u></font></span></p>
</div>
</div>

<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div></div>