Skip to content

Commit e71f243

Browse files
authored
[TableGen] Simplify MachineValueTypeSet::iterator::find_from_pos. NFC (llvm#169227)
Merge the SkipBits!=0 handling into the first iteration of the word loop. This is the same code structure used by BitVector::find_first_in.
1 parent c4254cd commit e71f243

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

llvm/utils/TableGen/Common/CodeGenDAGPatterns.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,19 @@ struct MachineValueTypeSet {
138138
private:
139139
unsigned find_from_pos(unsigned P) const {
140140
unsigned SkipWords = P / WordWidth;
141-
unsigned SkipBits = P % WordWidth;
142-
unsigned Count = SkipWords * WordWidth;
143-
144-
// If P is in the middle of a word, process it manually here, because
145-
// the trailing bits need to be masked off to use findFirstSet.
146-
if (SkipBits != 0) {
147-
WordType W = Set->Words[SkipWords];
148-
W &= maskLeadingOnes<WordType>(WordWidth - SkipBits);
149-
if (W != 0)
150-
return Count + llvm::countr_zero(W);
151-
Count += WordWidth;
152-
SkipWords++;
153-
}
154141

155142
for (unsigned i = SkipWords; i != NumWords; ++i) {
156143
WordType W = Set->Words[i];
144+
145+
// If P is in the middle of a word, process it manually here, because
146+
// the trailing bits need to be masked off to use countr_zero.
147+
if (i == SkipWords) {
148+
unsigned SkipBits = P % WordWidth;
149+
W &= maskTrailingZeros<WordType>(SkipBits);
150+
}
151+
157152
if (W != 0)
158-
return Count + llvm::countr_zero(W);
159-
Count += WordWidth;
153+
return i * WordWidth + llvm::countr_zero(W);
160154
}
161155
return Capacity;
162156
}

0 commit comments

Comments
 (0)