[llvm] r335788 - [X86] Make folding table checking threadsafe

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 27 14:47:03 PDT 2018


On Wed, Jun 27, 2018 at 11:30 PM Craig Topper <craig.topper at gmail.com>
wrote:

> Thanks!
>
> Does the similar code in X86EvexToVex.cpp also need this?
>

Yes. I think it didn't show up in my testing because the tests don't use
AVX512 (yet)


> Is what you did here better or worse the std::atomic used in ASSERT_SORTED
> in X86FloatingPoint.cpp?
>

The main difference is that ASSERT_SORTED might run the check multiple
times while the thread-safe static idiom only runs them once. Doesn't make
a difference in practice though. Thread-safe static is a bit more
heavyweight in cases where performance matters.


> ~Craig
>
>
> On Wed, Jun 27, 2018 at 2:06 PM Benjamin Kramer via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: d0k
>> Date: Wed Jun 27 14:01:53 2018
>> New Revision: 335788
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=335788&view=rev
>> Log:
>> [X86] Make folding table checking threadsafe
>>
>> This is a benign race, but tsan likes to complain about it. Just make it
>> happy.
>>
>> Modified:
>>     llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
>>
>> Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.cpp?rev=335788&r1=335787&r2=335788&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Target/X86/X86InstrInfo.cpp (original)
>> +++ llvm/trunk/lib/Target/X86/X86InstrInfo.cpp Wed Jun 27 14:01:53 2018
>> @@ -5413,8 +5413,7 @@ X86InstrInfo::X86InstrInfo(X86Subtarget
>>
>>  #ifndef NDEBUG
>>    // Make sure the tables are sorted.
>> -  static bool FoldTablesChecked = false;
>> -  if (!FoldTablesChecked) {
>> +  static bool LLVM_ATTRIBUTE_UNUSED FoldTablesChecked = [] {
>>      assert(std::is_sorted(std::begin(MemoryFoldTable2Addr),
>>                            std::end(MemoryFoldTable2Addr)) &&
>>             std::adjacent_find(std::begin(MemoryFoldTable2Addr),
>> @@ -5451,8 +5450,8 @@ X86InstrInfo::X86InstrInfo(X86Subtarget
>>                                std::end(MemoryFoldTable4)) ==
>>             std::end(MemoryFoldTable4) &&
>>             "MemoryFoldTable4 is not sorted and unique!");
>> -    FoldTablesChecked = true;
>> -  }
>> +    return true;
>> +  }();
>>  #endif
>>  }
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180627/66bd80da/attachment.html>


More information about the llvm-commits mailing list