[llvm] [TableGen] Simplify MachineValueTypeSet::iterator::find_from_pos. NFC (PR #169227)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 23 10:19:45 PST 2025
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/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.
>From 956f77a13a4a46a5ed0947d0e415d19ccc3beb56 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Sun, 23 Nov 2025 10:17:02 -0800
Subject: [PATCH] [TableGen] Simplify
MachineValueTypeSet::iterator::find_from_pos. NFC
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.
---
.../TableGen/Common/CodeGenDAGPatterns.h | 24 +++++++------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.h b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.h
index 8146f54cd3db5..633327e2f74e5 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.h
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.h
@@ -138,25 +138,19 @@ struct MachineValueTypeSet {
private:
unsigned find_from_pos(unsigned P) const {
unsigned SkipWords = P / WordWidth;
- unsigned SkipBits = P % WordWidth;
- unsigned Count = SkipWords * WordWidth;
-
- // If P is in the middle of a word, process it manually here, because
- // the trailing bits need to be masked off to use findFirstSet.
- if (SkipBits != 0) {
- WordType W = Set->Words[SkipWords];
- W &= maskLeadingOnes<WordType>(WordWidth - SkipBits);
- if (W != 0)
- return Count + llvm::countr_zero(W);
- Count += WordWidth;
- SkipWords++;
- }
for (unsigned i = SkipWords; i != NumWords; ++i) {
WordType W = Set->Words[i];
+
+ // If P is in the middle of a word, process it manually here, because
+ // the trailing bits need to be masked off to use countr_zero.
+ if (i == SkipWords) {
+ unsigned SkipBits = P % WordWidth;
+ W &= maskTrailingZeros<WordType>(SkipBits);
+ }
+
if (W != 0)
- return Count + llvm::countr_zero(W);
- Count += WordWidth;
+ return i * WordWidth + llvm::countr_zero(W);
}
return Capacity;
}
More information about the llvm-commits
mailing list