[CodeGen] Add constexpr and static_assert to fold64To16 (#192864)

This ensures the folding logic stability.
This commit is contained in:
Vitaly Buka 2026-04-20 19:07:34 -07:00 committed by GitHub
parent b39dfca39f
commit b906cf354b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -38,7 +38,7 @@ static uint64_t hashBlock(const MachineBasicBlock &MBB, bool HashOperands) {
}
/// Fold a 64-bit integer to a 16-bit one.
static uint16_t fold_64_to_16(const uint64_t Value) {
static constexpr uint16_t fold_64_to_16(const uint64_t Value) {
uint16_t Res = static_cast<uint16_t>(Value);
Res ^= static_cast<uint16_t>(Value >> 16);
Res ^= static_cast<uint16_t>(Value >> 32);
@ -46,6 +46,9 @@ static uint16_t fold_64_to_16(const uint64_t Value) {
return Res;
}
static_assert(fold_64_to_16(1) == 1);
static_assert(fold_64_to_16(12345678) == 25074);
INITIALIZE_PASS(MachineBlockHashInfo, "machine-block-hash",
"Machine Block Hash Analysis", true, true)