[llvm-branch-commits] [llvm] [LoongArch] Load suitable immediates with LU12I.W+SLLI.D (PR #242357)
Rong Mantle Bao via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Nov 13 23:42:49 PST 2026
================
@@ -32,6 +32,21 @@ LoongArchMatInt::InstSeq LoongArchMatInt::generateInstSeq(int64_t Val) {
return Insts;
}
+ // Values with lo32==0 and hi32 containing <=19 significant bits
+ // ("significant" as in "significant digits") can be loaded by SLLI.D-ing them
+ // into place.
+ // https://github.com/v8/v8/blob/cd5440417ebc15558b3fc626fb7c0cf1b6f97c66/src/codegen/loong64/macro-assembler-loong64.cc#L2083-L2085
+ if ((Val & 0xFFFFFFFF) == 0) {
+ const uint32_t Hi32 = static_cast<uint32_t>(Val >> 32);
+ const int TZC = llvm::countr_zero(Hi32);
+ const int LZC = llvm::countl_zero(Hi32);
+ if (TZC < 20 && ((TZC + LZC > 12) || (LZC == 0 && TZC + LZC >= 12))) {
+ Insts.push_back(Inst(LoongArch::LU12I_W, Hi32 >> TZC));
----------------
CSharperMantle wrote:
This is because LLVM wants a properly sign-extended `Hi32 >> TZC` here, while SM and V8 accept the raw bit pattern. The disassembly is somewhat misleading, i.e., LLVM/GCC's (expected) -524287 vs. V8's (current) 0x80001, which is why I didn't notice this when reading the updated FileCheck directives.
https://github.com/llvm/llvm-project/pull/242357
More information about the llvm-branch-commits
mailing list