Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PPC][MC] Restore support for case-insensitive register names #128525

Merged
merged 1 commit into from
Feb 24, 2025

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Feb 24, 2025

Lowercase the name before calling MatchRegisterName(), to restore support for using %R3 instead of %r3 and similar, matching the GNU assembler.

Fixes #126786.

Lowercase the name before calling MatchRegisterName(), to restore
support for using `%R3` instead of `%r3` and similar, matching the
GNU assembler.

Fixes llvm#126786.
@llvmbot
Copy link
Member

llvmbot commented Feb 24, 2025

@llvm/pr-subscribers-mc

@llvm/pr-subscribers-backend-powerpc

Author: Nikita Popov (nikic)

Changes

Lowercase the name before calling MatchRegisterName(), to restore support for using %R3 instead of %r3 and similar, matching the GNU assembler.

Fixes #126786.


Full diff: https://github.com/llvm/llvm-project/pull/128525.diff

2 Files Affected:

  • (modified) llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp (+8-5)
  • (added) llvm/test/MC/PowerPC/case-insensitive-regs.s (+11)
diff --git a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
index 016e4f9f7c6b6..a3646532c4530 100644
--- a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
+++ b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
@@ -1320,7 +1320,10 @@ MCRegister PPCAsmParser::matchRegisterName(int64_t &IntVal) {
   if (!getParser().getTok().is(AsmToken::Identifier))
     return MCRegister();
 
-  StringRef Name = getParser().getTok().getString();
+  // MatchRegisterName() expects lower-case registers, but we want to support
+  // case-insensitive spelling.
+  std::string NameBuf = getParser().getTok().getString().lower();
+  StringRef Name(NameBuf);
   MCRegister RegNo = MatchRegisterName(Name);
   if (!RegNo)
     return RegNo;
@@ -1329,15 +1332,15 @@ MCRegister PPCAsmParser::matchRegisterName(int64_t &IntVal) {
 
   // MatchRegisterName doesn't seem to have special handling for 64bit vs 32bit
   // register types.
-  if (Name.equals_insensitive("lr")) {
+  if (Name == "lr") {
     RegNo = isPPC64() ? PPC::LR8 : PPC::LR;
     IntVal = 8;
-  } else if (Name.equals_insensitive("ctr")) {
+  } else if (Name == "ctr") {
     RegNo = isPPC64() ? PPC::CTR8 : PPC::CTR;
     IntVal = 9;
-  } else if (Name.equals_insensitive("vrsave"))
+  } else if (Name == "vrsave")
     IntVal = 256;
-  else if (Name.starts_with_insensitive("r"))
+  else if (Name.starts_with("r"))
     RegNo = isPPC64() ? XRegs[IntVal] : RRegs[IntVal];
 
   getParser().Lex();
diff --git a/llvm/test/MC/PowerPC/case-insensitive-regs.s b/llvm/test/MC/PowerPC/case-insensitive-regs.s
new file mode 100644
index 0000000000000..f20a590318504
--- /dev/null
+++ b/llvm/test/MC/PowerPC/case-insensitive-regs.s
@@ -0,0 +1,11 @@
+# RUN: llvm-mc -triple powerpc64le-unknown-unknown %s 2>&1 | FileCheck %s
+
+# Test that upper case registers are accepted.
+
+# CHECK-LABEL: test:
+# CHECK-NEXT: ld 1, 0(3)
+# CHECK-NEXT: blr
+
+test:
+    ld %R1, 0(%R3)
+    blr

Copy link
Contributor

@lei137 lei137 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx!

@nikic nikic merged commit f1252f5 into llvm:main Feb 24, 2025
11 of 14 checks passed
@nikic nikic deleted the ppc-case-insensitive-regs branch February 24, 2025 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:PowerPC mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in dotnet9.0 builds caused by 23da169
3 participants