[llvm] eff105b - Bitset: remove some GCC<6.2 workarounds related to bitwise operators

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 18:44:03 PDT 2023


Author: Fangrui Song
Date: 2023-08-23T18:43:58-07:00
New Revision: eff105b1bde3333f0bea6d567dd09e44d4fb4b85

URL: https://github.com/llvm/llvm-project/commit/eff105b1bde3333f0bea6d567dd09e44d4fb4b85
DIFF: https://github.com/llvm/llvm-project/commit/eff105b1bde3333f0bea6d567dd09e44d4fb4b85.diff

LOG: Bitset: remove some GCC<6.2 workarounds related to bitwise operators

GCC<6.2 has been unsupported since April 2022 (commit 4c72deb613d9d8838785b431facb3eb480fb2f51).

X86TargetParser.cpp has another workaround that the other 2 nearly identical places don't have. Remove them as well.

Reviewed By: arsenm, craig.topper

Differential Revision: https://reviews.llvm.org/D158687

Added: 
    

Modified: 
    llvm/include/llvm/ADT/Bitset.h
    llvm/include/llvm/TargetParser/SubtargetFeature.h
    llvm/lib/TargetParser/X86TargetParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/Bitset.h b/llvm/include/llvm/ADT/Bitset.h
index 660c1037b6376f..839d3fe3abf6e1 100644
--- a/llvm/include/llvm/ADT/Bitset.h
+++ b/llvm/include/llvm/ADT/Bitset.h
@@ -56,23 +56,17 @@ class Bitset {
   }
 
   constexpr Bitset &set(unsigned I) {
-    // GCC <6.2 crashes if this is written in a single statement.
-    BitWord NewBits = Bits[I / BITWORD_SIZE] | (BitWord(1) << (I % BITWORD_SIZE));
-    Bits[I / BITWORD_SIZE] = NewBits;
+    Bits[I / BITWORD_SIZE] |= BitWord(1) << (I % BITWORD_SIZE);
     return *this;
   }
 
   constexpr Bitset &reset(unsigned I) {
-    // GCC <6.2 crashes if this is written in a single statement.
-    BitWord NewBits = Bits[I / BITWORD_SIZE] & ~(BitWord(1) << (I % BITWORD_SIZE));
-    Bits[I / BITWORD_SIZE] = NewBits;
+    Bits[I / BITWORD_SIZE] &= ~(BitWord(1) << (I % BITWORD_SIZE));
     return *this;
   }
 
   constexpr Bitset &flip(unsigned I) {
-    // GCC <6.2 crashes if this is written in a single statement.
-    BitWord NewBits = Bits[I / BITWORD_SIZE] ^ (BitWord(1) << (I % BITWORD_SIZE));
-    Bits[I / BITWORD_SIZE] = NewBits;
+    Bits[I / BITWORD_SIZE] ^= BitWord(1) << (I % BITWORD_SIZE);
     return *this;
   }
 
@@ -109,9 +103,8 @@ class Bitset {
   }
 
   constexpr Bitset &operator&=(const Bitset &RHS) {
-    for (unsigned I = 0, E = Bits.size(); I != E; ++I) {
+    for (unsigned I = 0, E = Bits.size(); I != E; ++I)
       Bits[I] &= RHS.Bits[I];
-    }
     return *this;
   }
   constexpr Bitset operator&(const Bitset &RHS) const {

diff  --git a/llvm/include/llvm/TargetParser/SubtargetFeature.h b/llvm/include/llvm/TargetParser/SubtargetFeature.h
index a898275c1493cc..e4dddfb78effbc 100644
--- a/llvm/include/llvm/TargetParser/SubtargetFeature.h
+++ b/llvm/include/llvm/TargetParser/SubtargetFeature.h
@@ -60,23 +60,17 @@ class FeatureBitset {
   }
 
   constexpr FeatureBitset &set(unsigned I) {
-    // GCC <6.2 crashes if this is written in a single statement.
-    uint64_t NewBits = Bits[I / 64] | (uint64_t(1) << (I % 64));
-    Bits[I / 64] = NewBits;
+    Bits[I / 64] |= uint64_t(1) << (I % 64);
     return *this;
   }
 
   constexpr FeatureBitset &reset(unsigned I) {
-    // GCC <6.2 crashes if this is written in a single statement.
-    uint64_t NewBits = Bits[I / 64] & ~(uint64_t(1) << (I % 64));
-    Bits[I / 64] = NewBits;
+    Bits[I / 64] &= ~(uint64_t(1) << (I % 64));
     return *this;
   }
 
   constexpr FeatureBitset &flip(unsigned I) {
-    // GCC <6.2 crashes if this is written in a single statement.
-    uint64_t NewBits = Bits[I / 64] ^ (uint64_t(1) << (I % 64));
-    Bits[I / 64] = NewBits;
+    Bits[I / 64] ^= uint64_t(1) << (I % 64);
     return *this;
   }
 
@@ -113,9 +107,8 @@ class FeatureBitset {
   }
 
   constexpr FeatureBitset &operator&=(const FeatureBitset &RHS) {
-    for (unsigned I = 0, E = Bits.size(); I != E; ++I) {
+    for (unsigned I = 0, E = Bits.size(); I != E; ++I)
       Bits[I] &= RHS.Bits[I];
-    }
     return *this;
   }
   constexpr FeatureBitset operator&(const FeatureBitset &RHS) const {

diff  --git a/llvm/lib/TargetParser/X86TargetParser.cpp b/llvm/lib/TargetParser/X86TargetParser.cpp
index 54f52e6e2b00a1..4c221bd85824b4 100644
--- a/llvm/lib/TargetParser/X86TargetParser.cpp
+++ b/llvm/lib/TargetParser/X86TargetParser.cpp
@@ -42,9 +42,7 @@ class FeatureBitset {
   }
 
   constexpr FeatureBitset &set(unsigned I) {
-    // GCC <6.2 crashes if this is written in a single statement.
-    uint32_t NewBits = Bits[I / 32] | (uint32_t(1) << (I % 32));
-    Bits[I / 32] = NewBits;
+    Bits[I / 32] |= uint32_t(1) << (I % 32);
     return *this;
   }
 
@@ -54,36 +52,26 @@ class FeatureBitset {
   }
 
   constexpr FeatureBitset &operator&=(const FeatureBitset &RHS) {
-    for (unsigned I = 0, E = std::size(Bits); I != E; ++I) {
-      // GCC <6.2 crashes if this is written in a single statement.
-      uint32_t NewBits = Bits[I] & RHS.Bits[I];
-      Bits[I] = NewBits;
-    }
+    for (unsigned I = 0, E = std::size(Bits); I != E; ++I)
+      Bits[I] &= RHS.Bits[I];
     return *this;
   }
 
   constexpr FeatureBitset &operator|=(const FeatureBitset &RHS) {
-    for (unsigned I = 0, E = std::size(Bits); I != E; ++I) {
-      // GCC <6.2 crashes if this is written in a single statement.
-      uint32_t NewBits = Bits[I] | RHS.Bits[I];
-      Bits[I] = NewBits;
-    }
+    for (unsigned I = 0, E = std::size(Bits); I != E; ++I)
+      Bits[I] |= RHS.Bits[I];
     return *this;
   }
 
-  // gcc 5.3 miscompiles this if we try to write this using operator&=.
   constexpr FeatureBitset operator&(const FeatureBitset &RHS) const {
-    FeatureBitset Result;
-    for (unsigned I = 0, E = std::size(Bits); I != E; ++I)
-      Result.Bits[I] = Bits[I] & RHS.Bits[I];
+    FeatureBitset Result = *this;
+    Result &= RHS;
     return Result;
   }
 
-  // gcc 5.3 miscompiles this if we try to write this using operator&=.
   constexpr FeatureBitset operator|(const FeatureBitset &RHS) const {
-    FeatureBitset Result;
-    for (unsigned I = 0, E = std::size(Bits); I != E; ++I)
-      Result.Bits[I] = Bits[I] | RHS.Bits[I];
+    FeatureBitset Result = *this;
+    Result |= RHS;
     return Result;
   }
 


        


More information about the llvm-commits mailing list