[llvm] [RISCV] Use uint64_t for Insn in getInstruction32 and getInstruction16. NFC (PR #146619)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 1 19:11:55 PDT 2025


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/146619

Insn is passed to decodeInstruction which is a template function based on the type of Insn. By using uint64_t we ensure only one version of decodeInstruction is created. This reduces the file size of RISCVDisassembler.cpp.o by ~25% in my local build.

This should get even more size benefit than #146593.

>From 52903cc2a26a6561cdcf4d8dcbc7bdd7ca7626f6 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 1 Jul 2025 19:04:54 -0700
Subject: [PATCH] [RISCV] Use uint64_t for Insn in getInstruction32 and
 getInstruction16. NFC

Insn is passed to decodeInstruction which is a template function
based on the type of Insn. By using uint64_t we ensure only one
version of decodeInstruction is created. This reduces the file size
of RISCVDisassembler.cpp.o by ~25% in my local build.

This should get even more size benefit than #146593.
---
 llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index 27e04c0cb1f8b..52061e96d0018 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -811,7 +811,9 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst &MI, uint64_t &Size,
   }
   Size = 4;
 
-  uint32_t Insn = support::endian::read32le(Bytes.data());
+  // Use uint64_t to match getInstruction48. decodeInstruction is templated
+  // on the Insn type.
+  uint64_t Insn = support::endian::read32le(Bytes.data());
 
   for (const DecoderListEntry &Entry : DecoderList32) {
     if (!Entry.haveContainedFeatures(STI.getFeatureBits()))
@@ -857,7 +859,9 @@ DecodeStatus RISCVDisassembler::getInstruction16(MCInst &MI, uint64_t &Size,
   }
   Size = 2;
 
-  uint32_t Insn = support::endian::read16le(Bytes.data());
+  // Use uint64_t to match getInstruction48. decodeInstruction is templated
+  // on the Insn type.
+  uint64_t Insn = support::endian::read16le(Bytes.data());
 
   for (const DecoderListEntry &Entry : DecoderList16) {
     if (!Entry.haveContainedFeatures(STI.getFeatureBits()))



More information about the llvm-commits mailing list