diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp --- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp +++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp @@ -444,74 +444,64 @@ Size = 0; return MCDisassembler::Fail; } + Size = 4; + Insn = support::endian::read32le(Bytes.data()); + if (STI.getFeatureBits()[RISCV::FeatureStdExtZdinx] && !STI.getFeatureBits()[RISCV::Feature64Bit]) { LLVM_DEBUG(dbgs() << "Trying RV32Zdinx table (Double in Integer and" "rv32)\n"); Result = decodeInstruction(DecoderTableRV32Zdinx32, MI, Insn, Address, this, STI); - if (Result != MCDisassembler::Fail) { - Size = 4; + if (Result != MCDisassembler::Fail) return Result; - } } - if (STI.getFeatureBits()[RISCV::FeatureStdExtZfinx]) { LLVM_DEBUG(dbgs() << "Trying RVZfinx table (Float in Integer):\n"); Result = decodeInstruction(DecoderTableRVZfinx32, MI, Insn, Address, this, STI); - if (Result != MCDisassembler::Fail) { - Size = 4; + if (Result != MCDisassembler::Fail) return Result; - } } if (STI.getFeatureBits()[RISCV::FeatureVendorXVentanaCondOps]) { LLVM_DEBUG(dbgs() << "Trying Ventana custom opcode table:\n"); Result = decodeInstruction(DecoderTableVentana32, MI, Insn, Address, this, STI); - if (Result != MCDisassembler::Fail) { - Size = 4; + if (Result != MCDisassembler::Fail) return Result; - } } if (STI.getFeatureBits()[RISCV::FeatureVendorXTHeadVdot]) { LLVM_DEBUG(dbgs() << "Trying XTHeadVdot custom opcode table:\n"); Result = decodeInstruction(DecoderTableTHeadV32, MI, Insn, Address, this, STI); - if (Result != MCDisassembler::Fail) { - Size = 4; + if (Result != MCDisassembler::Fail) return Result; - } } LLVM_DEBUG(dbgs() << "Trying RISCV32 table :\n"); - Result = decodeInstruction(DecoderTable32, MI, Insn, Address, this, STI); - Size = 4; - } else { - if (Bytes.size() < 2) { - Size = 0; - return MCDisassembler::Fail; - } - Insn = support::endian::read16le(Bytes.data()); + return decodeInstruction(DecoderTable32, MI, Insn, Address, this, STI); + } - if (!STI.getFeatureBits()[RISCV::Feature64Bit]) { - LLVM_DEBUG( - dbgs() << "Trying RISCV32Only_16 table (16-bit Instruction):\n"); - // Calling the auto-generated decoder function. - Result = decodeInstruction(DecoderTableRISCV32Only_16, MI, Insn, Address, - this, STI); - if (Result != MCDisassembler::Fail) { - Size = 2; - return Result; - } - } + if (Bytes.size() < 2) { + Size = 0; + return MCDisassembler::Fail; + } + Size = 2; + + Insn = support::endian::read16le(Bytes.data()); - LLVM_DEBUG(dbgs() << "Trying RISCV_C table (16-bit Instruction):\n"); + if (!STI.getFeatureBits()[RISCV::Feature64Bit]) { + LLVM_DEBUG( + dbgs() << "Trying RISCV32Only_16 table (16-bit Instruction):\n"); // Calling the auto-generated decoder function. - Result = decodeInstruction(DecoderTable16, MI, Insn, Address, this, STI); - Size = 2; + Result = decodeInstruction(DecoderTableRISCV32Only_16, MI, Insn, Address, + this, STI); + if (Result != MCDisassembler::Fail) + return Result; } - return Result; + LLVM_DEBUG(dbgs() << "Trying RISCV_C table (16-bit Instruction):\n"); + // Calling the auto-generated decoder function. + return decodeInstruction(DecoderTable16, MI, Insn, Address, this, STI); }