<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=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
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=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Hi James,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>No, I don’t think just switching to std::stable_sort() would solve the problem.  The elements that are “equal” based on the sort comparison would remain in their original order before the sort, which I believe is determined by the order they occur in the EquivalenceClasses member iterator, which is in turn determined by pointer order since the EquivalenceClasses members are stored in a set<Chain*> in this case.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Hopefully that makes sense.  If so, could you commit this change?<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Thanks,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>-Geoff<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><div style='mso-element:para-border-div;border:dashed #2F6FAB 1.0pt;padding:12.0pt 12.0pt 12.0pt 12.0pt;background:#F9F9F9'><p class=MsoNormal style='line-height:15.6pt;background:#F9F9F9;border:none;padding:0in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>--<o:p></o:p></span></p><p class=MsoNormal style='line-height:15.6pt;background:#F9F9F9;border:none;padding:0in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Geoff Berry<o:p></o:p></span></p><p class=MsoNormal style='line-height:15.6pt;background:#F9F9F9;border:none;padding:0in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Employee of Qualcomm Innovation Center, Inc.<o:p></o:p></span></p><p class=MsoNormal style='line-height:15.6pt;background:#F9F9F9;border:none;padding:0in'><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<o:p></o:p></span></p></div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> James Molloy [mailto:james@jamesmolloy.co.uk] <br><b>Sent:</b> Friday, January 30, 2015 3:41 AM<br><b>To:</b> reviews+D7265+public+9863efb7948c8628@reviews.llvm.org; gberry@codeaurora.org; james.molloy@arm.com; mcrosier@codeaurora.org; apazos@codeaurora.org<br><b>Cc:</b> llvm-commits@cs.uiuc.edu; kanheim@a-bix.com<br><b>Subject:</b> Re: [PATCH] AArch64: Make AArch64A57FPLoadBalancing output stable.<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Hi Geoff,<br><br>Thanks for fixing this! It looks ok as-is, but wouldn't switching simply from std::sort to std::stable_sort solve the problem easier? Stable_sort is used for this reason in other areas of the compiler.<br><br>Cheers,<br><br>James<o:p></o:p></p><div><p class=MsoNormal>On Fri, 30 Jan 2015 at 03:51, Geoff Berry <<a href="mailto:gberry@codeaurora.org">gberry@codeaurora.org</a>> wrote:<o:p></o:p></p><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><p class=MsoNormal>Hi jmolloy, mcrosier, apazos,<br><br>Add tie breaker to colorChainSet() sort so that processing order doesn't<br>depend on std::set order, which depends on pointer order, which is<br>unstable from run to run.<br><br>REPOSITORY<br>  rL LLVM<br><br><a href="http://reviews.llvm.org/D7265" target="_blank">http://reviews.llvm.org/D7265</a><br><br>Files:<br>  lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp<br><br>Index: lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp<br>===================================================================<br>--- lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp<br>+++ lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp<br>@@ -259,7 +259,7 @@<br>   }<br><br>   /// Return true if this chain starts before Other.<br>-  bool startsBefore(Chain *Other) {<br>+  bool startsBefore(const Chain *Other) const {<br>     return StartInstIdx < Other->StartInstIdx;<br>   }<br><br>@@ -431,10 +431,17 @@<br>   // chains that we cannot change before we look at those we can,<br>   // so the parity counter is updated and we know what color we should<br>   // change them to!<br>+  // Final tie-break with instruction order so pass output is stable (i.e. not<br>+  // dependent on malloc'd pointer values).<br>   std::sort(GV.begin(), GV.end(), [](const Chain *G1, const Chain *G2) {<br>       if (G1->size() != G2->size())<br>         return G1->size() > G2->size();<br>-      return G1->requiresFixup() > G2->requiresFixup();<br>+      if (G1->requiresFixup() != G2->requiresFixup())<br>+        return G1->requiresFixup() > G2->requiresFixup();<br>+      // Make sure startsBefore() produces a stable final order.<br>+      assert((G1 == G2 || (G1->startsBefore(G2) ^ G2->startsBefore(G1))) &&<br>+             "Starts before not total order!");<br>+      return G1->startsBefore(G2);<br>     });<br><br>   Color PreferredColor = Parity < 0 ? Color::Even : Color::Odd;<br><br>EMAIL PREFERENCES<br>  <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><o:p></o:p></p></blockquote></div></div></body></html>