[all-commits] [llvm/llvm-project] cdc2a0: [Mips] Simplify loadImmediate (NFC)
kazutakahirata via All-commits
all-commits at lists.llvm.org
Wed Jan 25 20:54:57 PST 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: cdc2a0473e90732245387344248b5487778f9b6f
https://github.com/llvm/llvm-project/commit/cdc2a0473e90732245387344248b5487778f9b6f
Author: Kazu Hirata <kazu at google.com>
Date: 2023-01-25 (Wed, 25 Jan 2023)
Changed paths:
M llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
Log Message:
-----------
[Mips] Simplify loadImmediate (NFC)
loadImmediate computes ShiftAmount in an unnecessarily complicated
manner. We just need to know the minimum right shift amount to bring
the immediate down to an unsigned 16-bit value, so
unsigned ShiftAmount = llvm::bit_width((uint64_t)ImmValue) - 16;
is sufficient. In other words, the following are all equivalent:
unsigned ShiftAmount = FirstSet - (15 - (LastSet - FirstSet));
unsigned ShiftAmount = llvm::countr_zero(IV) - (15 - (63 - llvm::countl_zero(IV) - llvm::countr_zero(IV)));
unsigned ShiftAmount = llvm::countr_zero(IV) - 15 + (63 - llvm::countl_zero(IV) - llvm::countr_zero(IV));
unsigned ShiftAmount = 48 - llvm::countl_zero(IV);
unsigned ShiftAmount = 64 - llvm::countl_zero(IV) - 16;
unsigned ShiftAmount = llvm::bit_width(IV) - 16;
where IV represents (uint64)ImmValue. I've also checked the
equivalence empirically up to 2u << 32.
More information about the All-commits
mailing list