<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif;">
<div>I field two bugs</div>
<div>
<div class="" data-block="true" data-editor="dke5o" data-offset-key="fv76i-0-0" style="color: rgb(29, 33, 41); font-family: helvetica, arial, sans-serif; font-size: 12px; font-variant-ligatures: normal; line-height: 16px; orphans: 2; white-space: pre-wrap; widows: 2; background-color: rgb(255, 255, 255);">
<div data-offset-key="fv76i-0-0" class="_1mf _1mj" style="position: relative; direction: ltr; display: inline; outline: none;">
<span data-offset-key="fv76i-0-0" style="color: rgb(59, 89, 152); cursor: pointer; text-decoration: none;"><span data-text="true"><a class="_esl" spellcheck="false" href="https://llvm.org/bugs/show_bug.cgi?id=28990" target="_blank" data-offset-key="fv76i-0-0" style="color: rgb(59, 89, 152); cursor: pointer; text-decoration: none;">https://llvm.org/bugs/show_bug.cgi?id=28990</a>
</span></span></div>
</div>
<div class="" data-block="true" data-editor="dke5o" data-offset-key="7nbtc-0-0" style="color: rgb(29, 33, 41); font-family: helvetica, arial, sans-serif; font-size: 12px; font-variant-ligatures: normal; line-height: 16px; orphans: 2; white-space: pre-wrap; widows: 2; background-color: rgb(255, 255, 255);">
<div data-offset-key="7nbtc-0-0" class="_1mf _1mj" style="position: relative; direction: ltr; display: inline; outline: none;">
<span data-offset-key="7nbtc-0-0" style="color: rgb(59, 89, 152); cursor: pointer; text-decoration: none;"><span data-text="true"><a class="_esl" spellcheck="false" href="https://llvm.org/bugs/show_bug.cgi?id=28991" target="_blank" data-offset-key="7nbtc-0-0" style="color: rgb(59, 89, 152); cursor: pointer; text-decoration: none;">https://llvm.org/bugs/show_bug.cgi?id=28991</a></span></span></div>
</div>
</div>
<div class="" data-block="true" data-editor="dke5o" data-offset-key="7nbtc-0-0" style="color: rgb(29, 33, 41); font-family: helvetica, arial, sans-serif; font-size: 12px; font-variant-ligatures: normal; line-height: 16px; orphans: 2; white-space: pre-wrap; widows: 2; background-color: rgb(255, 255, 255);">
<div data-offset-key="7nbtc-0-0" class="_1mf _1mj" style="position: relative; direction: ltr; display: inline; outline: none;">
<span data-offset-key="7nbtc-0-0" style="color: rgb(59, 89, 152); cursor: pointer; text-decoration: none;"><br>
</span></div>
</div>
<div class="" data-block="true" data-editor="dke5o" data-offset-key="7nbtc-0-0" style="color: rgb(29, 33, 41); font-family: helvetica, arial, sans-serif; font-size: 12px; font-variant-ligatures: normal; line-height: 16px; orphans: 2; white-space: pre-wrap; widows: 2;">
<div data-offset-key="7nbtc-0-0" class="_1mf _1mj" style="position: relative; direction: ltr; display: inline; outline: none;">
<span data-offset-key="7nbtc-0-0" style="color: rgb(59, 89, 152); cursor: pointer; text-decoration: none; background-color: rgb(255, 254, 254);">Which appear different but may be related.</span></div>
</div>
<div></div>
<div><br>
</div>
<span id="OLK_SRC_BODY_SECTION">
<div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<span style="font-weight:bold">From: </span>Xinliang David Li <<a href="mailto:xinliangli@gmail.com">xinliangli@gmail.com</a>><br>
<span style="font-weight:bold">Date: </span>Friday, August 12, 2016 at 11:15 AM<br>
<span style="font-weight:bold">To: </span>David Callahan <<a href="mailto:dcallahan@fb.com">dcallahan@fb.com</a>><br>
<span style="font-weight:bold">Cc: </span>LLVM Dev Mailing list <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>>, Dehao Chen <<a href="mailto:dehao@google.com">dehao@google.com</a>><br>
<span style="font-weight:bold">Subject: </span>Re: [llvm-dev] AutoFDO sample profiles v. SelectInst,<br>
</div>
<div><br>
</div>
<div>
<div>
<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="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Ddev&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=lFyiPUrFdOHdaobP7i4hoA&m=1vODYD_QOwdjhpMPgi5QwnjODVBWteag3lOcQgImh2k&s=2zUsLdPLscTj76IW8UOtjVjUiAb82ZV-Celctt7UKxc&e=" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</div>
</span>
</body>
</html>