aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2023-01-18 19:58:44 -0800
committerKazu Hirata <kazu@google.com>2023-01-18 19:58:44 -0800
commit83d56fb17a4d78471125df4249c3557bd4ddb5c2 (patch)
tree372e9ba7cf1ea4c7307d24c3efd35398796fb2b2 /mlir/lib/Bytecode/Reader/BytecodeReader.cpp
parent26f83b43b16a6efde8769d4bdf12779ffd8ef874 (diff)
downloadllvm-83d56fb17a4d78471125df4249c3557bd4ddb5c2.zip
llvm-83d56fb17a4d78471125df4249c3557bd4ddb5c2.tar.gz
llvm-83d56fb17a4d78471125df4249c3557bd4ddb5c2.tar.bz2
Drop the ZeroBehavior parameter from countLeadingZeros and the like (NFC)
This patch drops the ZeroBehavior parameter from bit counting functions like countLeadingZeros. ZeroBehavior specifies the behavior when the input to count{Leading,Trailing}Zeros is zero and when the input to count{Leading,Trailing}Ones is all ones. ZeroBehavior was first introduced on May 24, 2013 in commit eb91eac9fb866ab1243366d2e238b9961895612d. While that patch did not state the intention, I would guess ZeroBehavior was for performance reasons. The x86 machines around that time required a conditional branch to implement countLeadingZero<uint32_t> that returns the 32 on zero: test edi, edi je .LBB0_2 bsr eax, edi xor eax, 31 .LBB1_2: mov eax, 32 That is, we can remove the conditional branch if we don't care about the behavior on zero. IIUC, Intel's Haswell architecture, launched on June 4, 2013, introduced several bit manipulation instructions, including lzcnt and tzcnt, which eliminated the need for the conditional branch. I think it's time to retire ZeroBehavior as its utility is very limited. If you care about compilation speed, you should build LLVM with an appropriate -march= to take advantage of lzcnt and tzcnt. Even if not, modern host compilers should be able to optimize away quite a few conditional branches because the input is often known to be nonzero from dominating conditional branches. Differential Revision: https://reviews.llvm.org/D141798
Diffstat (limited to 'mlir/lib/Bytecode/Reader/BytecodeReader.cpp')
-rw-r--r--mlir/lib/Bytecode/Reader/BytecodeReader.cpp3
1 files changed, 1 insertions, 2 deletions
diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
index 8dded64..53e5547 100644
--- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
+++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
@@ -281,8 +281,7 @@ private:
// here because we only care about the first byte, and so that be actually
// get ctz intrinsic calls when possible (the `uint8_t` overload uses a loop
// implementation).
- uint32_t numBytes =
- llvm::countTrailingZeros<uint32_t>(result, llvm::ZB_Undefined);
+ uint32_t numBytes = llvm::countTrailingZeros<uint32_t>(result);
assert(numBytes > 0 && numBytes <= 7 &&
"unexpected number of trailing zeros in varint encoding");