[llvm] ca7e849 - [llvm] Use llvm::bit_floor (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 22 13:41:29 PST 2023
Author: Kazu Hirata
Date: 2023-01-22T13:41:23-08:00
New Revision: ca7e849720c2a02264865e79c42b0179049df144
URL: https://github.com/llvm/llvm-project/commit/ca7e849720c2a02264865e79c42b0179049df144
DIFF: https://github.com/llvm/llvm-project/commit/ca7e849720c2a02264865e79c42b0179049df144.diff
LOG: [llvm] Use llvm::bit_floor (NFC)
In all these cases, the arguments to Log2_32 are known to be nonzero,
so we don't have to worry about "1 << -1".
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/utils/TableGen/AsmWriterEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 37ffe140a814..8d0b90894cde 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -182,8 +182,7 @@ getCopyFromParts(SelectionDAG &DAG, const SDLoc &DL, const SDValue *Parts,
unsigned ValueBits = ValueVT.getSizeInBits();
// Assemble the power of 2 part.
- unsigned RoundParts =
- (NumParts & (NumParts - 1)) ? 1 << Log2_32(NumParts) : NumParts;
+ unsigned RoundParts = llvm::bit_floor(NumParts);
unsigned RoundBits = PartBits * RoundParts;
EVT RoundVT = RoundBits == ValueBits ?
ValueVT : EVT::getIntegerVT(*DAG.getContext(), RoundBits);
@@ -568,7 +567,7 @@ getCopyToParts(SelectionDAG &DAG, const SDLoc &DL, SDValue Val, SDValue *Parts,
// The number of parts is not a power of 2. Split off and copy the tail.
assert(PartVT.isInteger() && ValueVT.isInteger() &&
"Do not know what to expand to!");
- unsigned RoundParts = 1 << Log2_32(NumParts);
+ unsigned RoundParts = llvm::bit_floor(NumParts);
unsigned RoundBits = RoundParts * PartBits;
unsigned OddParts = NumParts - RoundParts;
SDValue OddVal = DAG.getNode(ISD::SRL, DL, ValueVT, Val,
diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp
index de4a8b4cbbd7..f2e4d15a2c75 100644
--- a/llvm/utils/TableGen/AsmWriterEmitter.cpp
+++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp
@@ -412,7 +412,7 @@ void AsmWriterEmitter::EmitGetMnemonic(
<< "_t Bits = 0;\n";
while (BytesNeeded != 0) {
// Figure out how big this table section needs to be, but no bigger than 4.
- unsigned TableSize = std::min(1 << Log2_32(BytesNeeded), 4);
+ unsigned TableSize = std::min(llvm::bit_floor(BytesNeeded), 4u);
BytesNeeded -= TableSize;
TableSize *= 8; // Convert to bits;
uint64_t Mask = (1ULL << TableSize) - 1;
More information about the llvm-commits
mailing list