[PATCH] D39995: [SelectionDAG] Make sorting predicate stronger to remove non-deterministic ordering

Mandeep Singh Grang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 18 10:55:10 PST 2017


mgrang marked an inline comment as done.
mgrang added inline comments.


================
Comment at: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:9551
               [](const CaseCluster &a, const CaseCluster &b) {
-      return a.Prob > b.Prob;
     });
----------------
fhahn wrote:
> hans wrote:
> > mgrang wrote:
> > > fhahn wrote:
> > > > I might be missing something but could we still end up with multiple clusters where `a.Prob == b.Prob && a.Low == b.Low` ? Then the order of those nodes would still be non-deterministic, no?
> > > @fhahn Thanks! I am not sure if we two clusters can have the same Low. How about I add another predicate a.High < b.High?
> > > 
> > > The fallback option is to simply change this to use std::stable_sort but I wanted to avoid this if we can simply get by adding stronger predicates.
> > The CaseClusters can't overlap, so having the same Low should not be possible.
> > 
> > I like this fix. Please expand the "Order cases by probability" comment to explain what's going on here. It would also be nice to have a test for this.
> > The CaseClusters can't overlap, so having the same Low should not be possible
> Ok great, thanks for confirming
> 
> 
I believe writing individual test cases for such scenarios is difficult as well as an overkill.

Once all failures uncovered by shuffling std::sort containers are fixed, I will push patches to change all std:sort to llvm::sort, which will shuffle containers by default in a +asserts build. Once that is done, the existing tests will automatically become test cases to uncover such non-determinism.


Repository:
  rL LLVM

https://reviews.llvm.org/D39995





More information about the llvm-commits mailing list