[llvm] efa1d0d - [LEB128] Mark error condition with LLVM_UNLIKELY
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 29 12:48:24 PST 2023
Author: Adrian Prantl
Date: 2023-11-29T12:47:43-08:00
New Revision: efa1d0d641c770267ff4c523a450334cd24ebe15
URL: https://github.com/llvm/llvm-project/commit/efa1d0d641c770267ff4c523a450334cd24ebe15
DIFF: https://github.com/llvm/llvm-project/commit/efa1d0d641c770267ff4c523a450334cd24ebe15.diff
LOG: [LEB128] Mark error condition with LLVM_UNLIKELY
Added:
Modified:
llvm/include/llvm/Support/LEB128.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/LEB128.h b/llvm/include/llvm/Support/LEB128.h
index 40b6cf79bacf758..7fc572b6ff06efc 100644
--- a/llvm/include/llvm/Support/LEB128.h
+++ b/llvm/include/llvm/Support/LEB128.h
@@ -135,15 +135,16 @@ inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = nullptr,
uint64_t Value = 0;
unsigned Shift = 0;
do {
- if (p == end) {
+ if (LLVM_UNLIKELY(p == end)) {
if (error)
*error = "malformed uleb128, extends past end";
Value = 0;
break;
}
uint64_t Slice = *p & 0x7f;
- if (Shift >= 63 && ((Shift == 63 && (Slice << Shift >> Shift) != Slice) ||
- (Shift > 63 && Slice != 0))) {
+ if (LLVM_UNLIKELY(Shift >= 63) &&
+ ((Shift == 63 && (Slice << Shift >> Shift) != Slice) ||
+ (Shift > 63 && Slice != 0))) {
if (error)
*error = "uleb128 too big for uint64";
Value = 0;
@@ -169,7 +170,7 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr,
unsigned Shift = 0;
uint8_t Byte;
do {
- if (p == end) {
+ if (LLVM_UNLIKELY(p == end)) {
if (error)
*error = "malformed sleb128, extends past end";
if (n)
@@ -178,8 +179,9 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr,
}
Byte = *p;
uint64_t Slice = Byte & 0x7f;
- if ((Shift >= 63) && ((Shift == 63 && Slice != 0 && Slice != 0x7f) ||
- (Shift > 63 && Slice != (Value < 0 ? 0x7f : 0x00)))) {
+ if (LLVM_UNLIKELY(Shift >= 63) &&
+ ((Shift == 63 && Slice != 0 && Slice != 0x7f) ||
+ (Shift > 63 && Slice != (Value < 0 ? 0x7f : 0x00)))) {
if (error)
*error = "sleb128 too big for int64";
if (n)
More information about the llvm-commits
mailing list