<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Mar 3, 2014, at 19:03, Chandler Carruth <<a href="mailto:chandlerc@gmail.com">chandlerc@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 3, 2014 at 6:11 PM, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I see. Shouldn’t it be a call to std::stable_sort(), then?</blockquote></div><br>Well, the whole point is that it *isn't* a call to stable_sort because the order of equal ranges shouldn't matter.</div>

<div class="gmail_extra"><br></div><div class="gmail_extra">In practice, we have messed up and made the order matter in several significant cases.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Right now, the order only matters in that it impacts the name de-duplication and the order of use-def chains created by SROA (much like serializing and deserializing through bitcode does), but I used this to debug a bunch of other more serious issues.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Even in a no-asserts build, the resulting binary isn't perfectly stable because we have some passes that are sensitive to incoming use-def ordering sadly. =/</div>

</div>
</blockquote></div><div><br></div><div>I was thinking about something akin to this (possibly less ugly ;-):</div><br><div><span style="font-family: Menlo-Regular;">#if __cplusplus >= 201103L && !defined(NDEBUG)</span><br style="font-family: Menlo-Regular;"><span style="font-family: Menlo-Regular;">  if (SROARandomShuffleSlices) {</span><br style="font-family: Menlo-Regular;"><span style="font-family: Menlo-Regular;">    std::mt19937 MT(static_cast<unsigned>(sys::TimeValue::now().msec()));</span><br style="font-family: Menlo-Regular;"><span style="font-family: Menlo-Regular;">    std::shuffle(Slices.begin(), Slices.end(), MT);</span><br style="font-family: Menlo-Regular;"><span style="font-family: Menlo-Regular;">    std::stable_sort(Slices.begin(), Slices.end());</span><br style="font-family: Menlo-Regular;"><span style="font-family: Menlo-Regular;">  } else</span></div><div><span style="font-family: Menlo-Regular;">#else</span><br style="font-family: Menlo-Regular;"><span style="font-family: Menlo-Regular;">  // Sort the uses. This arranges for the offsets to be in ascending order,</span><br><span style="font-family: Menlo-Regular;">  // and the sizes to be in descending order.</span><br style="font-family: Menlo-Regular;"><span style="font-family: Menlo-Regular;">  std::sort(Slices.begin(), Slices.end());</span></div><div><span style="font-family: Menlo-Regular;">#endif</span></div><div><span style="font-family: Menlo-Regular;"><br></span></div><div><font face="Menlo-Regular">-- adrian</font></div></body></html>