diff --git a/runtime/platform/globals.h b/runtime/platform/globals.h index 9078987dba9..5de25a94722 100644 --- a/runtime/platform/globals.h +++ b/runtime/platform/globals.h @@ -250,6 +250,17 @@ struct simd128_value_t { #error Automatic compiler detection failed. #endif +#if defined(__clang__) +#define DART_ASSUME(expr) __builtin_assume(expr) +#elif defined(__GNUC__) +#define DART_ASSUME(expr) \ + if (!(expr)) __builtin_unreachable() +#elif defined(_MSC_VER) +#define DART_ASSUME(expr) __assume(expr) +#else +#error Automatic compiler detection failed. +#endif + #ifdef _MSC_VER #elif __GNUC__ #define DART_HAS_COMPUTED_GOTO 1 diff --git a/runtime/vm/tagged_pointer.h b/runtime/vm/tagged_pointer.h index 8712990f69b..47601b6037c 100644 --- a/runtime/vm/tagged_pointer.h +++ b/runtime/vm/tagged_pointer.h @@ -457,6 +457,9 @@ inline intptr_t RawSmiValue(const SmiPtr raw_value) { static_cast(static_cast(raw_value)))); #endif ASSERT((value & kSmiTagMask) == kSmiTag); + // Let the C++ compiler know that it is safe to combine this right shift with + // a following left shift, such as often occurs for index scaling. + DART_ASSUME((value & kSmiTagMask) == kSmiTag); return (value >> kSmiTagShift); }