[llvm] 099c089 - [APInt] New member function setBitVal
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 2 13:57:22 PDT 2020
Author: Jay Foad
Date: 2020-09-02T21:40:31+01:00
New Revision: 099c089d4b4117fd654aa6e4dd544d7680fa80b9
URL: https://github.com/llvm/llvm-project/commit/099c089d4b4117fd654aa6e4dd544d7680fa80b9
DIFF: https://github.com/llvm/llvm-project/commit/099c089d4b4117fd654aa6e4dd544d7680fa80b9.diff
LOG: [APInt] New member function setBitVal
Differential Revision: https://reviews.llvm.org/D87033
Added:
Modified:
llvm/include/llvm/ADT/APInt.h
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/lib/MCA/HardwareUnits/RegisterFile.cpp
llvm/lib/Support/APInt.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index e3032a19f111..5e4206732f4d 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -1450,6 +1450,14 @@ class LLVM_NODISCARD APInt {
setBit(BitWidth - 1);
}
+ /// Set a given bit to a given value.
+ void setBitVal(unsigned BitPosition, bool BitValue) {
+ if (BitValue)
+ setBit(BitPosition);
+ else
+ clearBit(BitPosition);
+ }
+
/// Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
/// This function handles "wrap" case when \p loBit >= \p hiBit, and calls
/// setBits when \p loBit < \p hiBit.
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 60c0c20ffacd..a7816b8616e6 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -2603,13 +2603,9 @@ bool TargetLowering::SimplifyDemandedVectorElts(
KnownZero, TLO, Depth + 1))
return true;
- KnownUndef.clearBit(Idx);
- if (Scl.isUndef())
- KnownUndef.setBit(Idx);
+ KnownUndef.setBitVal(Idx, Scl.isUndef());
- KnownZero.clearBit(Idx);
- if (isNullConstant(Scl) || isNullFPConstant(Scl))
- KnownZero.setBit(Idx);
+ KnownZero.setBitVal(Idx, isNullConstant(Scl) || isNullFPConstant(Scl));
break;
}
diff --git a/llvm/lib/MCA/HardwareUnits/RegisterFile.cpp b/llvm/lib/MCA/HardwareUnits/RegisterFile.cpp
index 7ea5506f11d6..11a24a6889f1 100644
--- a/llvm/lib/MCA/HardwareUnits/RegisterFile.cpp
+++ b/llvm/lib/MCA/HardwareUnits/RegisterFile.cpp
@@ -196,15 +196,9 @@ void RegisterFile::addRegisterWrite(WriteRef Write,
// Update zero registers.
MCPhysReg ZeroRegisterID =
WS.clearsSuperRegisters() ? RegID : WS.getRegisterID();
- if (IsWriteZero) {
- ZeroRegisters.setBit(ZeroRegisterID);
- for (MCSubRegIterator I(ZeroRegisterID, &MRI); I.isValid(); ++I)
- ZeroRegisters.setBit(*I);
- } else {
- ZeroRegisters.clearBit(ZeroRegisterID);
- for (MCSubRegIterator I(ZeroRegisterID, &MRI); I.isValid(); ++I)
- ZeroRegisters.clearBit(*I);
- }
+ ZeroRegisters.setBitVal(ZeroRegisterID, IsWriteZero);
+ for (MCSubRegIterator I(ZeroRegisterID, &MRI); I.isValid(); ++I)
+ ZeroRegisters.setBitVal(*I, IsWriteZero);
// If this is move has been eliminated, then the call to tryEliminateMove
// should have already updated all the register mappings.
@@ -233,10 +227,7 @@ void RegisterFile::addRegisterWrite(WriteRef Write,
RegisterMappings[*I].second.AliasRegID = 0U;
}
- if (IsWriteZero)
- ZeroRegisters.setBit(*I);
- else
- ZeroRegisters.clearBit(*I);
+ ZeroRegisters.setBitVal(*I, IsWriteZero);
}
}
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 9a6f93feaa29..fc339de45af4 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -338,8 +338,7 @@ void APInt::flipAllBitsSlowCase() {
/// Toggles a given bit to its opposite value.
void APInt::flipBit(unsigned bitPosition) {
assert(bitPosition < BitWidth && "Out of the bit-width range!");
- if ((*this)[bitPosition]) clearBit(bitPosition);
- else setBit(bitPosition);
+ setBitVal(bitPosition, !(*this)[bitPosition]);
}
void APInt::insertBits(const APInt &subBits, unsigned bitPosition) {
@@ -393,12 +392,8 @@ void APInt::insertBits(const APInt &subBits, unsigned bitPosition) {
// General case - set/clear individual bits in dst based on src.
// TODO - there is scope for optimization here, but at the moment this code
// path is barely used so prefer readability over performance.
- for (unsigned i = 0; i != subBitWidth; ++i) {
- if (subBits[i])
- setBit(bitPosition + i);
- else
- clearBit(bitPosition + i);
- }
+ for (unsigned i = 0; i != subBitWidth; ++i)
+ setBitVal(bitPosition + i, subBits[i]);
}
void APInt::insertBits(uint64_t subBits, unsigned bitPosition, unsigned numBits) {
More information about the llvm-commits
mailing list