<div dir="ltr"><div>If LLVM uses containers of pointers, then be aware that the relative ordering of pointers is completely undefined.  It will vary between Linux and Windows, and it will even vary from run to run on the same system due to address space layout randomization (ASLR).</div><div><br></div><div>I have noticed with past releases (3.7?) that LLVM bitcode output is not ASLR-stable. I am not sure if this is still the case.  As MartinO had remarked, this is not necessarily "wrong" in that the code generated is still functionally correct, but it may complicate testing or other applications such as incremental compilation.</div><div><br></div><div>Interestingly, even through the bitcode is not stable, I have also noticed that if you write out assembly from the bitcode, then the assembly output from two different runs WILL be identical, even if the bitcode is not.</div><div><br></div><div>I noticed this while attempting to use a hash over the bitcode as a gating condition for incremental compilation. (Don't recompile if hash has not changed since the last time bitcode was generated.) Using bitcode directly resulted in gratuitous recompilation due to the ASLR-instability. I subsequently used a hash over my own intermediate code format, which I ensured was ASLR stable, and that works just fine.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 15, 2018 at 6:31 AM, xuruobin 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 link="#0563C1" vlink="#954F72" lang="EN-US">
<div class="m_5971161519327600157WordSection1">
<p class="MsoNormal">Hi MartinO,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks for your answer, but I still cannot figure out why std::stable_sort generated two different result. As far as I know,
<span style="font-size:9.5pt;font-family:"Arial",sans-serif;background:white">the order of equivalent elements is guaranteed to be preserved</span> by std::stable_sort regardless of VC++ and libstdc++.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Ruobin.<u></u><u></u></p>
<p class="MsoNormal"><span style="color:#1f497d"><u></u> <u></u></span></p>
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-family:"\005fae\008f6f\0096c5\009ed1",sans-serif" lang="ZH-CN">发件人</span></b><b><span style="font-family:"\005fae\008f6f\0096c5\009ed1",sans-serif">:</span></b><span style="font-family:"\005fae\008f6f\0096c5\009ed1",sans-serif"> Martin J. O'Riordan [mailto:<a href="mailto:MartinO@theheart.ie" target="_blank">MartinO@theheart.ie</a>]
<br>
<b><span lang="ZH-CN">发送时间</span>:</b> 2018<span lang="ZH-CN">年</span>8<span lang="ZH-CN">月</span>14<span lang="ZH-CN">日</span> 20:12<br>
<b><span lang="ZH-CN">收件人</span>:</b> xuruobin <<a href="mailto:xuruobin@huawei.com" target="_blank">xuruobin@huawei.com</a>>; 'LLVM Developers' <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b><span lang="ZH-CN">抄送</span>:</b> Yuchao (Michael) <<a href="mailto:michael.yuchao@huawei.com" target="_blank">michael.yuchao@huawei.com</a>><br>
<b><span lang="ZH-CN">主题</span>:</b> RE: [llvm-dev] Assembly mimatch between windows and linux llvm.(probably caused by sort algorithm)<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634" lang="EN-IE">Hi Ruobin,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634" lang="EN-IE"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634" lang="EN-IE">I have had similar problems in the past, and it is generally caused by the hash value being used to determine relative
 ordering between two (or more) values which are otherwise considered equal.  Since the implementation of the hashing is different between VC++ and the one in ‘libstdc++’ or LibC++, this can result in apparently non-deterministic ordering.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634" lang="EN-IE"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634" lang="EN-IE">In my case the problem occurred when sorting BBs during scheduling, but it is likely that you are seeing something similar. 
 I don’t remember the exact details, but I think I resolved it by using the BB# when my ordering test indicated that the values were equal.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634" lang="EN-IE"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634" lang="EN-IE">If it is any consolation, this does not generally result in “wrong” code, just “different” code.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634" lang="EN-IE"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634" lang="EN-IE">    MartinO<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634" lang="EN-IE"><u></u> <u></u></span></p>
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b>From:</b> llvm-dev [<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">mailto:llvm-dev-bounces@<wbr>lists.llvm.org</a>]
<b>On Behalf Of </b>xuruobin via llvm-dev<br>
<b>Sent:</b> 13 August 2018 13:44<br>
<b>To:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Cc:</b> Yuchao (Michael) <<a href="mailto:michael.yuchao@huawei.com" target="_blank">michael.yuchao@huawei.com</a>><br>
<b>Subject:</b> [llvm-dev] Assembly mimatch between windows and linux llvm.(probably caused by sort algorithm)<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><span lang="EN-IE"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">To whom it may concern,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">I’m running some testcases(A and B) in Linux LLVM(built in Ubuntu16.04) and Windows LLVM(built by Visual Studio 2015), both of which were LLVM 4.0.0 and built with same source codes, but I got different assembly
 files(A_Linux != A_Windows, B_Linux = B_Windows). Privacy reasons prevent me from sharing my testcases here, sorry.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">I compared debug information and found the root cause in MachinePipliner.cpp that Node orders differed after sort algorithm.
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">There were two `std::sort` in this file and when I replaced them with ‘std::stable_sort’, these two assembly files became the same but other assembly files differed(A_Linux = A_Windows, B_Linux != B_Windows).<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">I cannot figure out the reason and could you give me some advice why this happened and what sort algorithm should I use to get exactly same assembly files?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">Best regards,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">Ruobin<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></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>