[llvm] [ADT] BitVector: give `subsetOf(RHS)` name to `!test(RHS)` (NFC) (PR #170875)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 5 08:01:49 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
@llvm/pr-subscribers-backend-hexagon
Author: Anatoly Trosinenko (atrosinenko)
<details>
<summary>Changes</summary>
Define `LHS.subsetOf(RHS)` as a more descriptive name for `!LHS.test(RHS)`
and update the existing callers to use that name.
---
Full diff: https://github.com/llvm/llvm-project/pull/170875.diff
8 Files Affected:
- (modified) bolt/lib/Passes/PAuthGadgetScanner.cpp (+1-1)
- (modified) llvm/include/llvm/ADT/BitVector.h (+4-1)
- (modified) llvm/include/llvm/ADT/SmallBitVector.h (+5-1)
- (modified) llvm/lib/Analysis/StackLifetime.cpp (+2-2)
- (modified) llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp (+1-1)
- (modified) llvm/lib/CodeGen/StackColoring.cpp (+2-2)
- (modified) llvm/lib/Target/Hexagon/HexagonBitSimplify.cpp (+1-2)
- (modified) llvm/lib/Target/Hexagon/HexagonGenInsert.cpp (+1-2)
``````````diff
diff --git a/bolt/lib/Passes/PAuthGadgetScanner.cpp b/bolt/lib/Passes/PAuthGadgetScanner.cpp
index 01b350b2f11fe..d38a7fadb0767 100644
--- a/bolt/lib/Passes/PAuthGadgetScanner.cpp
+++ b/bolt/lib/Passes/PAuthGadgetScanner.cpp
@@ -547,7 +547,7 @@ class SrcSafetyAnalysis {
// Being trusted is a strictly stronger property than being
// safe-to-dereference.
- assert(!Next.TrustedRegs.test(Next.SafeToDerefRegs) &&
+ assert(Next.TrustedRegs.subsetOf(Next.SafeToDerefRegs) &&
"SafeToDerefRegs should contain all TrustedRegs");
return Next;
diff --git a/llvm/include/llvm/ADT/BitVector.h b/llvm/include/llvm/ADT/BitVector.h
index cc3f3a9226395..f4645c18a93f0 100644
--- a/llvm/include/llvm/ADT/BitVector.h
+++ b/llvm/include/llvm/ADT/BitVector.h
@@ -550,7 +550,7 @@ class BitVector {
return *this;
}
- /// test - Check if (This - RHS) is zero.
+ /// test - Check if (This - RHS) is non-zero.
/// This is the same as reset(RHS) and any().
bool test(const BitVector &RHS) const {
unsigned ThisWords = Bits.size();
@@ -567,6 +567,9 @@ class BitVector {
return false;
}
+ /// subsetOf - Check if This is a subset of RHS.
+ bool subsetOf(const BitVector &RHS) const { return !test(RHS); }
+
template <class F, class... ArgTys>
static BitVector &apply(F &&f, BitVector &Out, BitVector const &Arg,
ArgTys const &...Args) {
diff --git a/llvm/include/llvm/ADT/SmallBitVector.h b/llvm/include/llvm/ADT/SmallBitVector.h
index 5b2a5221b791f..978dc3f073031 100644
--- a/llvm/include/llvm/ADT/SmallBitVector.h
+++ b/llvm/include/llvm/ADT/SmallBitVector.h
@@ -552,7 +552,8 @@ class SmallBitVector {
return *this;
}
- /// Check if (This - RHS) is zero. This is the same as reset(RHS) and any().
+ /// Check if (This - RHS) is non-zero.
+ /// This is the same as reset(RHS) and any().
bool test(const SmallBitVector &RHS) const {
if (isSmall() && RHS.isSmall())
return (getSmallBits() & ~RHS.getSmallBits()) != 0;
@@ -571,6 +572,9 @@ class SmallBitVector {
return false;
}
+ /// Check if This is a subset of RHS.
+ bool subsetOf(const SmallBitVector &RHS) const { return !test(RHS); }
+
SmallBitVector &operator|=(const SmallBitVector &RHS) {
resize(std::max(size(), RHS.size()));
if (isSmall() && RHS.isSmall())
diff --git a/llvm/lib/Analysis/StackLifetime.cpp b/llvm/lib/Analysis/StackLifetime.cpp
index 1e20fca965ace..30e0316b882cc 100644
--- a/llvm/lib/Analysis/StackLifetime.cpp
+++ b/llvm/lib/Analysis/StackLifetime.cpp
@@ -173,7 +173,7 @@ void StackLifetime::calculateLocalLiveness() {
BitsIn.resize(NumAllocas, true);
// Update block LiveIn set, noting whether it has changed.
- if (BitsIn.test(BlockInfo.LiveIn)) {
+ if (!BitsIn.subsetOf(BlockInfo.LiveIn)) {
BlockInfo.LiveIn |= BitsIn;
}
@@ -198,7 +198,7 @@ void StackLifetime::calculateLocalLiveness() {
}
// Update block LiveOut set, noting whether it has changed.
- if (BitsIn.test(BlockInfo.LiveOut)) {
+ if (!BitsIn.subsetOf(BlockInfo.LiveOut)) {
Changed = true;
BlockInfo.LiveOut |= BitsIn;
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
index c7d45897c403b..d6b06b83207c7 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -164,7 +164,7 @@ bool DwarfExpression::addMachineReg(const TargetRegisterInfo &TRI,
// If this sub-register has a DWARF number and we haven't covered
// its range, and its range covers the value, emit a DWARF piece for it.
- if (Offset < MaxSize && CurSubReg.test(Coverage)) {
+ if (Offset < MaxSize && !CurSubReg.subsetOf(Coverage)) {
// Emit a piece for any gap in the coverage.
if (Offset > CurPos)
DwarfRegs.push_back(Register::createSubRegister(
diff --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp
index f7862641d94b9..4ec8b8b3646c1 100644
--- a/llvm/lib/CodeGen/StackColoring.cpp
+++ b/llvm/lib/CodeGen/StackColoring.cpp
@@ -815,13 +815,13 @@ void StackColoring::calculateLocalLiveness() {
LocalLiveOut |= BlockInfo.Begin;
// Update block LiveIn set, noting whether it has changed.
- if (LocalLiveIn.test(BlockInfo.LiveIn)) {
+ if (!LocalLiveIn.subsetOf(BlockInfo.LiveIn)) {
changed = true;
BlockInfo.LiveIn |= LocalLiveIn;
}
// Update block LiveOut set, noting whether it has changed.
- if (LocalLiveOut.test(BlockInfo.LiveOut)) {
+ if (!LocalLiveOut.subsetOf(BlockInfo.LiveOut)) {
changed = true;
BlockInfo.LiveOut |= LocalLiveOut;
}
diff --git a/llvm/lib/Target/Hexagon/HexagonBitSimplify.cpp b/llvm/lib/Target/Hexagon/HexagonBitSimplify.cpp
index 557a0a3f27819..848337457c997 100644
--- a/llvm/lib/Target/Hexagon/HexagonBitSimplify.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonBitSimplify.cpp
@@ -137,8 +137,7 @@ namespace {
return !Bits.any();
}
bool includes(const RegisterSet &Rs) const {
- // A.test(B) <=> A-B != {}
- return !Rs.Bits.test(Bits);
+ return Rs.Bits.subsetOf(Bits);
}
bool intersects(const RegisterSet &Rs) const {
return Bits.anyCommon(Rs.Bits);
diff --git a/llvm/lib/Target/Hexagon/HexagonGenInsert.cpp b/llvm/lib/Target/Hexagon/HexagonGenInsert.cpp
index ff876f6595350..18fcd6a4873fb 100644
--- a/llvm/lib/Target/Hexagon/HexagonGenInsert.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonGenInsert.cpp
@@ -153,8 +153,7 @@ namespace {
return !BitVector::any();
}
bool includes(const RegisterSet &Rs) const {
- // A.BitVector::test(B) <=> A-B != {}
- return !Rs.BitVector::test(*this);
+ return Rs.BitVector::subsetOf(*this);
}
bool intersects(const RegisterSet &Rs) const {
return BitVector::anyCommon(Rs);
``````````
</details>
https://github.com/llvm/llvm-project/pull/170875
More information about the llvm-commits
mailing list