Unify sorted asserts to use the existing atomic pattern

These are all benign races and only visible in !NDEBUG. tsan complains
about it, but a simple atomic bool is sufficient to make it happy.

llvm-svn: 335823
diff --git a/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp b/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
index 439ba9e..2f3390d 100644
--- a/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
+++ b/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
@@ -415,11 +415,11 @@
 static const NEONLdStTableEntry *LookupNEONLdSt(unsigned Opcode) {
 #ifndef NDEBUG
   // Make sure the table is sorted.
-  static bool TableChecked = false;
-  if (!TableChecked) {
+  static std::atomic<bool> TableChecked(false);
+  if (!TableChecked.load(std::memory_order_relaxed)) {
     assert(std::is_sorted(std::begin(NEONLdStTable), std::end(NEONLdStTable)) &&
            "NEONLdStTable is not sorted!");
-    TableChecked = true;
+    TablesChecked.store(true, std::memory_order_relaxed);
   }
 #endif
 
diff --git a/llvm/lib/Target/X86/X86EvexToVex.cpp b/llvm/lib/Target/X86/X86EvexToVex.cpp
index fb7217b..8352ebc 100644
--- a/llvm/lib/Target/X86/X86EvexToVex.cpp
+++ b/llvm/lib/Target/X86/X86EvexToVex.cpp
@@ -239,15 +239,15 @@
 
 #ifndef NDEBUG
   // Make sure the tables are sorted.
-  static bool TableChecked = false;
-  if (!TableChecked) {
+  static std::atomic<bool> TableChecked(false);
+  if (!TableChecked.load(std::memory_order_relaxed)) {
     assert(std::is_sorted(std::begin(X86EvexToVex128CompressTable),
                           std::end(X86EvexToVex128CompressTable)) &&
            "X86EvexToVex128CompressTable is not sorted!");
     assert(std::is_sorted(std::begin(X86EvexToVex256CompressTable),
                           std::end(X86EvexToVex256CompressTable)) &&
            "X86EvexToVex256CompressTable is not sorted!");
-    TableChecked = true;
+    TablesChecked.store(true, std::memory_order_relaxed);
   }
 #endif
 
diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp
index 7096e82..7492de2 100644
--- a/llvm/lib/Target/X86/X86InstrInfo.cpp
+++ b/llvm/lib/Target/X86/X86InstrInfo.cpp
@@ -5413,7 +5413,8 @@
 
 #ifndef NDEBUG
   // Make sure the tables are sorted.
-  static bool LLVM_ATTRIBUTE_UNUSED FoldTablesChecked = [] {
+  static std::atomic<bool> FoldTablesChecked(false);
+  if (!FoldTablesChecked.load(std::memory_order_relaxed)) {
     assert(std::is_sorted(std::begin(MemoryFoldTable2Addr),
                           std::end(MemoryFoldTable2Addr)) &&
            std::adjacent_find(std::begin(MemoryFoldTable2Addr),
@@ -5450,8 +5451,8 @@
                               std::end(MemoryFoldTable4)) ==
            std::end(MemoryFoldTable4) &&
            "MemoryFoldTable4 is not sorted and unique!");
-    return true;
-  }();
+    FoldTablesChecked.store(true, std::memory_order_relaxed);
+  }
 #endif
 }