[llvm] [RISCV] Merge RegStart with RegEnd in parseRegListCommon. NFC (PR #133867)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 31 23:19:53 PDT 2025


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

We only need to keep track of the last register seen. We never need the first register once we've parsed. Currently if s0/x8 is used RegStart will point to that and not ra/s1 so it already isn't the start.

>From 0db3c3395358644c47e52ec2d537f024437913f0 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Mon, 31 Mar 2025 23:17:04 -0700
Subject: [PATCH] [RISCV] Merge RegStart with RegEnd in parseRegListCommon.

We only need to keep track of the last register seen. We never need
the first register once we've parsed. Currently if s0/x8 is used
RegStart will point to that and not ra/s1 so it already isn't the start.
---
 llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index c1670326143e3..d34463ef9c2b1 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -2579,9 +2579,8 @@ ParseStatus RISCVAsmParser::parseRegListCommon(OperandVector &Operands,
     return Error(getLoc(), "register list must start from 'ra' or 'x1'");
 
   StringRef RegName = getLexer().getTok().getIdentifier();
-  MCRegister RegStart = matchRegisterNameHelper(RegName);
-  MCRegister RegEnd;
-  if (RegStart != RISCV::X1)
+  MCRegister RegEnd = matchRegisterNameHelper(RegName);
+  if (RegEnd != RISCV::X1)
     return Error(getLoc(), "register list must start from 'ra' or 'x1'");
   getLexer().Lex();
 
@@ -2602,10 +2601,10 @@ ParseStatus RISCVAsmParser::parseRegListCommon(OperandVector &Operands,
     if (getLexer().isNot(AsmToken::Identifier))
       return Error(getLoc(), "invalid register");
     StringRef RegName = getLexer().getTok().getIdentifier();
-    RegStart = matchRegisterNameHelper(RegName);
-    if (!RegStart)
+    RegEnd = matchRegisterNameHelper(RegName);
+    if (!RegEnd)
       return Error(getLoc(), "invalid register");
-    if (RegStart != RISCV::X8)
+    if (RegEnd != RISCV::X8)
       return Error(getLoc(),
                    "continuous register list must start from 's0' or 'x8'");
     getLexer().Lex(); // eat reg
@@ -2663,9 +2662,6 @@ ParseStatus RISCVAsmParser::parseRegListCommon(OperandVector &Operands,
   if (parseToken(AsmToken::RCurly, "register list must end with '}'"))
     return ParseStatus::Failure;
 
-  if (!RegEnd)
-    RegEnd = RegStart;
-
   auto Encode = RISCVZC::encodeRlist(RegEnd, IsEABI);
   assert(Encode != RISCVZC::INVALID_RLIST);
   if (MustIncludeS0)



More information about the llvm-commits mailing list