<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:微软雅黑;
panose-1:2 11 5 3 2 2 4 2 2 4;}
@font-face
{font-family:"\@微软雅黑";
panose-1:2 11 5 3 2 2 4 2 2 4;}
@font-face
{font-family:"Book Antiqua";
panose-1:2 4 6 2 5 3 5 3 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle18
{mso-style-type:personal;
font-family:"Book Antiqua",serif;
color:#943634;
font-weight:normal;
font-style:normal;
text-decoration:none none;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hi MartinO,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></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++.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Ruobin.<o:p></o:p></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="ZH-CN" style="font-family:"微软雅黑",sans-serif">发件人</span></b><b><span style="font-family:"微软雅黑",sans-serif">:</span></b><span style="font-family:"微软雅黑",sans-serif"> Martin J. O'Riordan [mailto:MartinO@theheart.ie]
<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 <xuruobin@huawei.com>; 'LLVM Developers' <llvm-dev@lists.llvm.org><br>
<b><span lang="ZH-CN">抄送</span>:</b> Yuchao (Michael) <michael.yuchao@huawei.com><br>
<b><span lang="ZH-CN">主题</span>:</b> RE: [llvm-dev] Assembly mimatch between windows and linux llvm.(probably caused by sort algorithm)<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-IE" style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US">Hi Ruobin,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE" style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE" style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE" style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE" style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE" style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE" style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US">If it is any consolation, this does not generally result in “wrong” code, just “different” code.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE" style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE" style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US"> MartinO<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE" style="font-size:12.0pt;font-family:"Book Antiqua",serif;color:#943634;mso-fareast-language:EN-US"><o:p> </o:p></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">mailto:llvm-dev-bounces@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">llvm-dev@lists.llvm.org</a><br>
<b>Cc:</b> Yuchao (Michael) <<a href="mailto:michael.yuchao@huawei.com">michael.yuchao@huawei.com</a>><br>
<b>Subject:</b> [llvm-dev] Assembly mimatch between windows and linux llvm.(probably caused by sort algorithm)<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">To whom it may concern,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></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.<o:p></o:p></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.
<o:p></o:p></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).<o:p></o:p></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?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">Best regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:14.0pt">Ruobin<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>