<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;">I see. Shouldn’t it be a call to std::stable_sort(), then?<div><br></div><div>-- adrian</div><div><br><div><div>On Mar 3, 2014, at 18:09, Reid Kleckner <<a href="mailto:rnk@google.com">rnk@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">If there are equal elements in the list, this should jostle them around a bit.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 3, 2014 at 4:59 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"><div class="HOEnZb"><div class="h5"><br>
On Feb 24, 2014, at 19:59, Chandler Carruth <<a href="mailto:chandlerc@gmail.com">chandlerc@gmail.com</a>> wrote:<br>
<br>
> Author: chandlerc<br>
> Date: Mon Feb 24 21:59:29 2014<br>
> New Revision: 202106<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=202106&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=202106&view=rev</a><br>
> Log:<br>
> [SROA] Add a debugging tool which shuffles the slices sequence prior to<br>
> sorting it. This helps uncover latent reliance on the original ordering<br>
> which aren't guaranteed to be preserved by std::sort (but often are),<br>
> and which are based on the use-def chain orderings which also aren't<br>
> (technically) guaranteed.<br>
><br>
> Only available in C++11 debug builds, and behind a flag to prevent noise<br>
> at the moment, but this is generally useful so figured I'd put it in the<br>
> tree rather than keeping it out-of-tree.<br>
><br>
> Modified:<br>
>    llvm/trunk/lib/Transforms/Scalar/SROA.cpp<br>
><br>
> Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=202106&r1=202105&r2=202106&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=202106&r1=202105&r2=202106&view=diff</a><br>

> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Mon Feb 24 21:59:29 2014<br>
> @@ -51,10 +51,17 @@<br>
> #include "llvm/Support/Debug.h"<br>
> #include "llvm/Support/ErrorHandling.h"<br>
> #include "llvm/Support/MathExtras.h"<br>
> +#include "llvm/Support/TimeValue.h"<br>
> #include "llvm/Support/raw_ostream.h"<br>
> #include "llvm/Transforms/Utils/Local.h"<br>
> #include "llvm/Transforms/Utils/PromoteMemToReg.h"<br>
> #include "llvm/Transforms/Utils/SSAUpdater.h"<br>
> +<br>
> +#if __cplusplus >= 201103L && !defined(NDEBUG)<br>
> +// We only use this for a debug check in C++11<br>
> +#include <random><br>
> +#endif<br>
> +<br>
> using namespace llvm;<br>
><br>
> STATISTIC(NumAllocasAnalyzed, "Number of allocas analyzed for replacement");<br>
> @@ -73,6 +80,11 @@ STATISTIC(NumVectorized, "Number of vect<br>
> static cl::opt<bool><br>
> ForceSSAUpdater("force-ssa-updater", cl::init(false), cl::Hidden);<br>
><br>
> +/// Hidden option to enable randomly shuffling the slices to help uncover<br>
> +/// instability in their order.<br>
> +static cl::opt<bool> SROARandomShuffleSlices("sroa-random-shuffle-slices",<br>
> +                                             cl::init(false), cl::Hidden);<br>
> +<br>
> namespace {<br>
> /// \brief A custom IRBuilder inserter which prefixes all names if they are<br>
> /// preserved.<br>
> @@ -690,6 +702,13 @@ AllocaSlices::AllocaSlices(const DataLay<br>
>                               std::mem_fun_ref(&Slice::isDead)),<br>
>                Slices.end());<br>
><br>
> +#if __cplusplus >= 201103L && !defined(NDEBUG)<br>
> +  if (SROARandomShuffleSlices) {<br>
> +    std::mt19937 MT(static_cast<unsigned>(sys::TimeValue::now().msec()));<br>
> +    std::shuffle(Slices.begin(), Slices.end(), MT);<br>
> +  }<br>
> +#endif<br>
> +<br>
>   // Sort the uses. This arranges for the offsets to be in ascending order,<br>
>   // and the sizes to be in descending order.<br>
>   std::sort(Slices.begin(), Slices.end());<br>
<br>
</div></div>Maybe I’m missing something obvious here, but isn’t the shuffle a no-op if it is followed immediately by a sort?<br>
<span class="HOEnZb"><font color="#888888"><br>
-- adrian<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">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><br>
</div></div></blockquote></div><br></div>
</blockquote></div><br></div></body></html>