[llvm] r318680 - [SelectionDAG] Make sorting predicate stronger to remove non-deterministic ordering

Grang, Mandeep Singh via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 20 11:18:59 PST 2017


Thanks for informing me Hans. I have reverted my patch until I find a 
fix: https://reviews.llvm.org/rL318686.

--Mandeep


On 11/20/2017 11:04 AM, Hans Wennborg wrote:
> The buildbots are sad:
> http://bb.pgr.jp/builders/test-llvm-i686-linux-RA/builds/1330/
>
> On Mon, Nov 20, 2017 at 10:46 AM, Mandeep Singh Grang via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>> Author: mgrang
>> Date: Mon Nov 20 10:46:11 2017
>> New Revision: 318680
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=318680&view=rev
>> Log:
>> [SelectionDAG] Make sorting predicate stronger to remove non-deterministic ordering
>>
>> Summary:
>> This fixes failures in the following tests uncovered by D39245:
>>          LLVM :: CodeGen/ARM/ifcvt3.ll
>>          LLVM :: CodeGen/ARM/switch-minsize.ll
>>          LLVM :: CodeGen/X86/switch.ll
>>
>> Reviewers: hans, efriedma
>>
>> Reviewed By: hans
>>
>> Subscribers: fhahn, aemerson, kristof.beyls, llvm-commits
>>
>> Differential Revision: https://reviews.llvm.org/D39995
>>
>> Modified:
>>      llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
>>
>> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=318680&r1=318679&r2=318680&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Mon Nov 20 10:46:11 2017
>> @@ -9350,10 +9350,12 @@ bool SelectionDAGBuilder::buildBitTests(
>>
>>     BitTestInfo BTI;
>>     std::sort(CBV.begin(), CBV.end(), [](const CaseBits &a, const CaseBits &b) {
>> -    // Sort by probability first, number of bits second.
>> +    // Sort by probability first, number of bits second, bit mask third.
>>       if (a.ExtraProb != b.ExtraProb)
>>         return a.ExtraProb > b.ExtraProb;
>> -    return a.Bits > b.Bits;
>> +    if (a.Bits != b.Bits)
>> +      return a.Bits > b.Bits;
>> +    return a.Mask < b.Mask;
>>     });
>>
>>     for (auto &CB : CBV) {
>> @@ -9542,10 +9544,13 @@ void SelectionDAGBuilder::lowerWorkItem(
>>     }
>>
>>     if (TM.getOptLevel() != CodeGenOpt::None) {
>> -    // Order cases by probability so the most likely case will be checked first.
>> +    // Here, we order cases by probability so the most likely case will be
>> +    // checked first. However, two clusters can have the same probability in
>> +    // which case their relative ordering is non-deterministic. So we use Low
>> +    // as a tie-breaker as clusters are guaranteed to never overlap.
>>       std::sort(W.FirstCluster, W.LastCluster + 1,
>>                 [](const CaseCluster &a, const CaseCluster &b) {
>> -      return a.Prob > b.Prob;
>> +      return a.Prob != b.Prob ? a.Prob > b.Prob : a.Low < b.Low;
>>       });
>>
>>       // Rearrange the case blocks so that the last one falls through if possible
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list