<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="m_1860601532149800485m_5233375800023946560h5"><br><div><br></div></div></div><div>One of our definitions of non-determinism is simply "output from command line tools should always be bit identical given identical inputs", which is suitable for content-based caching build systems like Bazel.</div></div></div></div></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Just to point out: These systems already often have to ignore whitespace differences, etc.  </div><div><br></div><div>I'd also argue any of these content-based caching build systems is going to be rarely used if they require every single tool that uses them to produce bit identical output (IE boiling the ocean), as opposed to letting the tools define what identical means or something.</div></div></div></div></blockquote></div></div><div><br>This seems inconsistent with my understanding of LLVM's (& Google's, re: Bazel) goals..<br></div></div></div></blockquote><div><br></div><div>My point is that they are certainly welcome to try this path, but it's been tried before.</div><div>There are reasons ccache, et al have various "slop" modes.</div><div><br></div><div>I suspect, but can't prove, a system that is so rigid will not be adopted in practice.</div><div>(So far: Only one major player has done so, and did so by fiat!)</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br>So far as I know, LLVM has fixed pretty much any "the same input causes different output bits, even if they're semantically equivalent" bug that's reported (well, they're considered bugs at least - sometimes takes a while for someone to prioritize them)<br></div></div></div></blockquote><div><br></div><div>Which, again, i'm fine with as long as we don't muck up passes a ton to do it.  I'd rather design them properly and fix things like "random limits", etc.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br>While it doesn't outright break Bazel when that property doesn't hold, I believe it can cause more cache invalidation than is ideal (eg: build system evicts an object file from the cache, but still has the resulting executable in the cache - to do the link step it goes to rebuild the objects*, finds a new/different object and then reruns the link because of it)<br><br>Also for LLVM testing purposes, I believe any case where the output text/bits are different are usually fixed so the tests are reliable.<br></div></div></div></blockquote><div><br></div><div>FWIW: In the cases i cited the tests can already be made reliable in the face of these differences :)</div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br>* maybe this scenario doesn't really happen - if Bazel assumes reproducibility is transitive, it could observe that the input hashes are the same so it doesn't need to run the task at all if all the other object files are available - could just assume the resulting binary would be the same as the one it already has<br></div></div></div></blockquote><div><br></div><div>Right.</div><div>This is definitely faster :)</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span class=""><div><br></div></span><div>No optimizations should change, but I think it'd be pretty difficult to support testing that pass (granted with LLVM's testing approach, at least that would be fairly isolated to only the tests for the pass - it wouldn't pollute other pass tests with nondeterminism of output, so might not be too painful)<br></div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I don't think you can say such a pass is broken.<br></div></div></div></div></blockquote></span><div><br>I kind of would say it's broken. </div></div></div></blockquote><div>Why?<br></div><div>It makes literally no semantic change to the code that is incorrect.</div><div>This is precisely why my view is that if you want *output* to look a certain way, you need to cause the *output emission* to handle that.  </div><div><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>Arbitrarily reordering, I'd be OK with, nondeterministically reordering would seem not OK to me (again, based on the sentiments I've heard expressed from Chandler and others (though I may've misunderstood/may be incorrectly representing their perspective) on the project/my best understanding of the goals, etc - and I tend to agree with them, but could well be wrong)<br></div></div></div></blockquote><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div> </div><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div>Hence I think if you want such constraints, they need to be placed on output orderings, not on what passes do.<br></div></div></div></div></blockquote></span><div><br>Ah, hmm, maybe there's a point of confusion. Changing the order of BBs in a Function would change the output ordering, right?</div></div></div></blockquote><div><br></div><div>Yes</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div> Presumably that would be reflected in printed IR, bitcode, and possibly in block layout (at least at -O0, but I could imagine some aspects of that ordering leak out even when LLVM does advanced block layout optimizations).<br></div></div></div></blockquote><div><br></div><div>Again, any ordering changes that cause optimization differences are clear bugs in the pass.</div><div>Yes, i know that this means we have a lot of bugs :)  I consider any case where, due to a limit, identical [1]  code optimizes differently, to be a bug. You should too!</div><div><br></div><div>block1:</div><div>foo</div><div>block2:</div><div>bar</div><div>should optimize the same as</div><div><br></div><div>block2:</div><div>bar</div><div>block1:</div><div>foo</div><div><br></div><div><br></div><div>Let me try to put this another way: <br></div><div>My argument is precisely that code that is literally identical (but subject to expression in multiple textual forms) should be optimized the same way, and that's the avoidance of non-determinism you should shoot for, *not* the simple subset of "same crap in, same crap out" :P.</div><div><br></div><div>This form does *not* preclude the output form from being different for things that meet [1], and if you want the output form to look the same, that is a function of ordering output, not of "stopping passes from doing things":</div><div>If you aren't ordering output, and just try to get the "same crap in produces same crap out" form of non-determinism, you are going to get screwed by all the random limits, etc, anyway as you improve the passes in that you will have gratuitous, but deterministic, output change, and probably some non-determinism anyway.  </div><div><br></div><div>[1]   For the purposes of this discussion, let's define this  to mean the following:<br>Code that is subject to multiple textual forms that have precisely the same meaning to llvm, but generate different orderings in our containers/output:</div><div><br>IE textual input</div><div>block1: </div><div>foo</div><div>block2:</div><div>bar</div><div><br></div><div>should generate the same results as as textual input:</div><div><br></div><div>block2:</div><div>bar</div><div>block1:</div><div>foo</div><div><br></div><div><br></div><div><br></div></div></div></div>