Skip to content

Commit eff105b

Browse files
committed
Bitset: remove some GCC<6.2 workarounds related to bitwise operators
GCC<6.2 has been unsupported since April 2022 (commit 4c72deb). 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
1 parent 749f36d commit eff105b

File tree

3 files changed

+17
-43
lines changed

3 files changed

+17
-43
lines changed

llvm/include/llvm/ADT/Bitset.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,17 @@ class Bitset {
5656
}
5757

5858
constexpr Bitset &set(unsigned I) {
59-
// GCC <6.2 crashes if this is written in a single statement.
60-
BitWord NewBits = Bits[I / BITWORD_SIZE] | (BitWord(1) << (I % BITWORD_SIZE));
61-
Bits[I / BITWORD_SIZE] = NewBits;
59+
Bits[I / BITWORD_SIZE] |= BitWord(1) << (I % BITWORD_SIZE);
6260
return *this;
6361
}
6462

6563
constexpr Bitset &reset(unsigned I) {
66-
// GCC <6.2 crashes if this is written in a single statement.
67-
BitWord NewBits = Bits[I / BITWORD_SIZE] & ~(BitWord(1) << (I % BITWORD_SIZE));
68-
Bits[I / BITWORD_SIZE] = NewBits;
64+
Bits[I / BITWORD_SIZE] &= ~(BitWord(1) << (I % BITWORD_SIZE));
6965
return *this;
7066
}
7167

7268
constexpr Bitset &flip(unsigned I) {
73-
// GCC <6.2 crashes if this is written in a single statement.
74-
BitWord NewBits = Bits[I / BITWORD_SIZE] ^ (BitWord(1) << (I % BITWORD_SIZE));
75-
Bits[I / BITWORD_SIZE] = NewBits;
69+
Bits[I / BITWORD_SIZE] ^= BitWord(1) << (I % BITWORD_SIZE);
7670
return *this;
7771
}
7872

@@ -109,9 +103,8 @@ class Bitset {
109103
}
110104

111105
constexpr Bitset &operator&=(const Bitset &RHS) {
112-
for (unsigned I = 0, E = Bits.size(); I != E; ++I) {
106+
for (unsigned I = 0, E = Bits.size(); I != E; ++I)
113107
Bits[I] &= RHS.Bits[I];
114-
}
115108
return *this;
116109
}
117110
constexpr Bitset operator&(const Bitset &RHS) const {

llvm/include/llvm/TargetParser/SubtargetFeature.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,17 @@ class FeatureBitset {
6060
}
6161

6262
constexpr FeatureBitset &set(unsigned I) {
63-
// GCC <6.2 crashes if this is written in a single statement.
64-
uint64_t NewBits = Bits[I / 64] | (uint64_t(1) << (I % 64));
65-
Bits[I / 64] = NewBits;
63+
Bits[I / 64] |= uint64_t(1) << (I % 64);
6664
return *this;
6765
}
6866

6967
constexpr FeatureBitset &reset(unsigned I) {
70-
// GCC <6.2 crashes if this is written in a single statement.
71-
uint64_t NewBits = Bits[I / 64] & ~(uint64_t(1) << (I % 64));
72-
Bits[I / 64] = NewBits;
68+
Bits[I / 64] &= ~(uint64_t(1) << (I % 64));
7369
return *this;
7470
}
7571

7672
constexpr FeatureBitset &flip(unsigned I) {
77-
// GCC <6.2 crashes if this is written in a single statement.
78-
uint64_t NewBits = Bits[I / 64] ^ (uint64_t(1) << (I % 64));
79-
Bits[I / 64] = NewBits;
73+
Bits[I / 64] ^= uint64_t(1) << (I % 64);
8074
return *this;
8175
}
8276

@@ -113,9 +107,8 @@ class FeatureBitset {
113107
}
114108

115109
constexpr FeatureBitset &operator&=(const FeatureBitset &RHS) {
116-
for (unsigned I = 0, E = Bits.size(); I != E; ++I) {
110+
for (unsigned I = 0, E = Bits.size(); I != E; ++I)
117111
Bits[I] &= RHS.Bits[I];
118-
}
119112
return *this;
120113
}
121114
constexpr FeatureBitset operator&(const FeatureBitset &RHS) const {

llvm/lib/TargetParser/X86TargetParser.cpp

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ class FeatureBitset {
4242
}
4343

4444
constexpr FeatureBitset &set(unsigned I) {
45-
// GCC <6.2 crashes if this is written in a single statement.
46-
uint32_t NewBits = Bits[I / 32] | (uint32_t(1) << (I % 32));
47-
Bits[I / 32] = NewBits;
45+
Bits[I / 32] |= uint32_t(1) << (I % 32);
4846
return *this;
4947
}
5048

@@ -54,36 +52,26 @@ class FeatureBitset {
5452
}
5553

5654
constexpr FeatureBitset &operator&=(const FeatureBitset &RHS) {
57-
for (unsigned I = 0, E = std::size(Bits); I != E; ++I) {
58-
// GCC <6.2 crashes if this is written in a single statement.
59-
uint32_t NewBits = Bits[I] & RHS.Bits[I];
60-
Bits[I] = NewBits;
61-
}
55+
for (unsigned I = 0, E = std::size(Bits); I != E; ++I)
56+
Bits[I] &= RHS.Bits[I];
6257
return *this;
6358
}
6459

6560
constexpr FeatureBitset &operator|=(const FeatureBitset &RHS) {
66-
for (unsigned I = 0, E = std::size(Bits); I != E; ++I) {
67-
// GCC <6.2 crashes if this is written in a single statement.
68-
uint32_t NewBits = Bits[I] | RHS.Bits[I];
69-
Bits[I] = NewBits;
70-
}
61+
for (unsigned I = 0, E = std::size(Bits); I != E; ++I)
62+
Bits[I] |= RHS.Bits[I];
7163
return *this;
7264
}
7365

74-
// gcc 5.3 miscompiles this if we try to write this using operator&=.
7566
constexpr FeatureBitset operator&(const FeatureBitset &RHS) const {
76-
FeatureBitset Result;
77-
for (unsigned I = 0, E = std::size(Bits); I != E; ++I)
78-
Result.Bits[I] = Bits[I] & RHS.Bits[I];
67+
FeatureBitset Result = *this;
68+
Result &= RHS;
7969
return Result;
8070
}
8171

82-
// gcc 5.3 miscompiles this if we try to write this using operator&=.
8372
constexpr FeatureBitset operator|(const FeatureBitset &RHS) const {
84-
FeatureBitset Result;
85-
for (unsigned I = 0, E = std::size(Bits); I != E; ++I)
86-
Result.Bits[I] = Bits[I] | RHS.Bits[I];
73+
FeatureBitset Result = *this;
74+
Result |= RHS;
8775
return Result;
8876
}
8977

0 commit comments

Comments
 (0)