[llvm] [RISCV][NFC] Combine redundant 'if' statements (PR #70423)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 29 23:06:46 PDT 2023
https://github.com/knightXun updated https://github.com/llvm/llvm-project/pull/70423
>From 432c32d8f914b5cd5674af85d434cc15cbbf025a Mon Sep 17 00:00:00 2001
From: xuknight <badgangkiller at gmail.com>
Date: Fri, 27 Oct 2023 15:21:16 +0800
Subject: [PATCH] [RISCV][NFC] Combine redundant 'if' statements
Due to the repetitive occurrence of two consecutive simple "if" statements in the code, they can be merged together.
Additionally, there is a single simple "switch-case" statement, but since there are only a few cases,
it can be replaced with an "if" statement.
---
.../RISCV/Disassembler/RISCVDisassembler.cpp | 24 +++++--------------
1 file changed, 6 insertions(+), 18 deletions(-)
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index e5ce029449a8c69..14187cca7d86ea5 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -196,10 +196,7 @@ static DecodeStatus DecodeVRRegisterClass(MCInst &Inst, uint32_t RegNo,
static DecodeStatus DecodeVRM2RegisterClass(MCInst &Inst, uint32_t RegNo,
uint64_t Address,
const MCDisassembler *Decoder) {
- if (RegNo >= 32)
- return MCDisassembler::Fail;
-
- if (RegNo % 2)
+ if (RegNo >= 32 || RegNo % 2)
return MCDisassembler::Fail;
const RISCVDisassembler *Dis =
@@ -216,10 +213,7 @@ static DecodeStatus DecodeVRM2RegisterClass(MCInst &Inst, uint32_t RegNo,
static DecodeStatus DecodeVRM4RegisterClass(MCInst &Inst, uint32_t RegNo,
uint64_t Address,
const MCDisassembler *Decoder) {
- if (RegNo >= 32)
- return MCDisassembler::Fail;
-
- if (RegNo % 4)
+ if (RegNo >= 32 || RegNo % 4)
return MCDisassembler::Fail;
const RISCVDisassembler *Dis =
@@ -236,10 +230,7 @@ static DecodeStatus DecodeVRM4RegisterClass(MCInst &Inst, uint32_t RegNo,
static DecodeStatus DecodeVRM8RegisterClass(MCInst &Inst, uint32_t RegNo,
uint64_t Address,
const MCDisassembler *Decoder) {
- if (RegNo >= 32)
- return MCDisassembler::Fail;
-
- if (RegNo % 8)
+ if (RegNo >= 32 || RegNo % 8)
return MCDisassembler::Fail;
const RISCVDisassembler *Dis =
@@ -257,15 +248,12 @@ static DecodeStatus decodeVMaskReg(MCInst &Inst, uint64_t RegNo,
uint64_t Address,
const MCDisassembler *Decoder) {
MCRegister Reg = RISCV::NoRegister;
- switch (RegNo) {
- default:
+ if (RegNo > 2) {
return MCDisassembler::Fail;
- case 0:
+ } else if (RegNo == 0) {
Reg = RISCV::V0;
- break;
- case 1:
- break;
}
+
Inst.addOperand(MCOperand::createReg(Reg));
return MCDisassembler::Success;
}
More information about the llvm-commits
mailing list