[clang] [llvm] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

Stefan Pintilie via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 1 18:50:12 PDT 2023


https://github.com/stefanp-ibm updated https://github.com/llvm/llvm-project/pull/70255

>From c57979d3d86362df239d3d3ff8cda124d40bb79d Mon Sep 17 00:00:00 2001
From: Stefan Pintilie <stefanp at ca.ibm.com>
Date: Wed, 25 Oct 2023 15:21:11 -0500
Subject: [PATCH 1/5] [PowerPC] Add an alias for -mregnames so that full
 register names used in assembly.

This option already exists on GCC and so it is being added to LLVM so that we
use the same option as them.
---
 clang/include/clang/Driver/Options.td         |  4 +
 clang/lib/Basic/Targets/PPC.cpp               |  6 ++
 clang/lib/Basic/Targets/PPC.h                 |  1 +
 .../test/CodeGen/PowerPC/ppc-full-reg-names.c | 78 +++++++++++++++++++
 .../PowerPC/MCTargetDesc/PPCInstPrinter.cpp   | 15 ++--
 .../PowerPC/MCTargetDesc/PPCInstPrinter.h     |  5 +-
 llvm/lib/Target/PowerPC/PPC.td                |  4 +
 .../CodeGen/PowerPC/ppc-full-reg-names.ll     | 62 +++++++++++++++
 8 files changed, 167 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
 create mode 100644 llvm/test/CodeGen/PowerPC/ppc-full-reg-names.ll

diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..74b92b76bc2d866 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4802,6 +4802,10 @@ def mrop_protect : Flag<["-"], "mrop-protect">,
     Group<m_ppc_Features_Group>;
 def mprivileged : Flag<["-"], "mprivileged">,
     Group<m_ppc_Features_Group>;
+def mregnames : Flag<["-"], "mregnames">, Group<m_ppc_Features_Group>,
+                Visibility<[ClangOption]>;
+def mno_regnames : Flag<["-"], "mno-regnames">, Group<m_ppc_Features_Group>,
+                   Visibility<[ClangOption]>;
 } // let Flags = [TargetSpecific]
 def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">,
   Group<m_ppc_Features_Group>,
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 0d87a3a4e8c20f3..fa8f598c1843461 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -89,6 +89,8 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
       IsISA3_1 = true;
     } else if (Feature == "+quadword-atomics") {
       HasQuadwordAtomics = true;
+    } else if (Feature == "+regnames") {
+      FullRegisterNames = true;
     }
     // TODO: Finish this list and add an assert that we've handled them
     // all.
@@ -547,6 +549,9 @@ bool PPCTargetInfo::initFeatureMap(
   // off by default.
   Features["aix-small-local-exec-tls"] = false;
 
+  // By default full register names are not used in assembly.
+  Features["regnames"] = false;
+
   Features["spe"] = llvm::StringSwitch<bool>(CPU)
                         .Case("8548", true)
                         .Case("e500", true)
@@ -696,6 +701,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
       .Case("isa-v30-instructions", IsISA3_0)
       .Case("isa-v31-instructions", IsISA3_1)
       .Case("quadword-atomics", HasQuadwordAtomics)
+      .Case("regnames", FullRegisterNames)
       .Default(false);
 }
 
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 4d62673ba7fb8c5..ddef057bb306cad 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -80,6 +80,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
   bool IsISA3_0 = false;
   bool IsISA3_1 = false;
   bool HasQuadwordAtomics = false;
+  bool FullRegisterNames = false;
 
 protected:
   std::string ABI;
diff --git a/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c b/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
new file mode 100644
index 000000000000000..c1bd22c1134c9a7
--- /dev/null
+++ b/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
@@ -0,0 +1,78 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -emit-llvm -mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -emit-llvm -mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+
+// Also check the assembly to make sure that the full names are used.
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMFULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMFULLNAMES
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMFULLNAMES
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMNOFULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMNOFULLNAMES
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMNOFULLNAMES
+
+
+
+// FULLNAMES-LABEL: @IntNames
+// FULLNAMES-SAME:  #0
+// NOFULLNAMES-LABEL: @IntNames
+// NOFULLNAMES-SAME:  #0
+// ASMFULLNAMES-LABEL: IntNames:
+// ASMFULLNAMES:         add r3, r4, r3
+// ASMFULLNAMES:         blr
+// ASMNOFULLNAMES-LABEL: IntNames:
+// ASMNOFULLNAMES:         add 3, 4, 3
+// ASMNOFULLNAMES:         blr
+int IntNames(int a, int b) {
+  return a + b;
+}
+
+// FULLNAMES-LABEL: @FPNames
+// FULLNAMES-SAME:  #0
+// NOFULLNAMES-LABEL: @FPNames
+// NOFULLNAMES-SAME:  #0
+// ASMFULLNAMES-LABEL: FPNames:
+// ASMFULLNAMES:         xsadddp f1, f1, f2
+// ASMFULLNAMES:         blr
+// ASMNOFULLNAMES-LABEL: FPNames:
+// ASMNOFULLNAMES:         xsadddp 1, 1, 2
+// ASMNOFULLNAMES:         blr
+double FPNames(double a, double b) {
+  return a + b;
+}
+
+// FULLNAMES-LABEL: @VecNames
+// FULLNAMES-SAME:  #0
+// NOFULLNAMES-LABEL: @VecNames
+// NOFULLNAMES-SAME:  #0
+// ASMFULLNAMES-LABEL: VecNames:
+// ASMFULLNAMES:         xvaddsp vs34, vs34, vs35
+// ASMFULLNAMES:         blr
+// ASMNOFULLNAMES-LABEL: VecNames:
+// ASMNOFULLNAMES:         xvaddsp 34, 34, 35
+// ASMNOFULLNAMES:         blr
+vector float VecNames(vector float a, vector float b) {
+  return a + b;
+}
+
+// FULLNAMES: attributes #0 = {
+// FULLNAMES-SAME: +regnames
+// NOFULLNAMES: attributes #0 = {
+// NOFULLNAMES-SAME: -regnames
+
+
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
index 0ee7f9f49843172..17498627a84fdfd 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
@@ -614,9 +614,11 @@ bool PPCInstPrinter::showRegistersWithPercentPrefix(const char *RegName) const {
 /// getVerboseConditionalRegName - This method expands the condition register
 /// when requested explicitly or targetting Darwin.
 const char *PPCInstPrinter::getVerboseConditionRegName(unsigned RegNum,
-                                                       unsigned RegEncoding)
+                                                       unsigned RegEncoding,
+                                                       const MCSubtargetInfo &STI)
                                                        const {
-  if (!FullRegNames)
+                                                         // __SP__
+  if (!FullRegNames && !STI.hasFeature(PPC::FeatureFullRegisterNames))
     return nullptr;
   if (RegNum < PPC::CR0EQ || RegNum > PPC::CR7UN)
     return nullptr;
@@ -635,8 +637,9 @@ const char *PPCInstPrinter::getVerboseConditionRegName(unsigned RegNum,
 
 // showRegistersWithPrefix - This method determines whether registers
 // should be number-only or include the prefix.
-bool PPCInstPrinter::showRegistersWithPrefix() const {
-  return FullRegNamesWithPercent || FullRegNames;
+bool PPCInstPrinter::showRegistersWithPrefix(const MCSubtargetInfo &STI) const {
+  return FullRegNamesWithPercent || FullRegNames ||
+         STI.hasFeature(PPC::FeatureFullRegisterNames);
 }
 
 void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
@@ -648,12 +651,12 @@ void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
       Reg = PPC::getRegNumForOperand(MII.get(MI->getOpcode()), Reg, OpNo);
 
     const char *RegName;
-    RegName = getVerboseConditionRegName(Reg, MRI.getEncodingValue(Reg));
+    RegName = getVerboseConditionRegName(Reg, MRI.getEncodingValue(Reg), STI);
     if (RegName == nullptr)
      RegName = getRegisterName(Reg);
     if (showRegistersWithPercentPrefix(RegName))
       O << "%";
-    if (!showRegistersWithPrefix())
+    if (!showRegistersWithPrefix(STI))
       RegName = PPC::stripRegisterPrefix(RegName);
 
     O << RegName;
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h
index 6ba3eb4c79dc990..2e29971a20fc593 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h
@@ -22,9 +22,10 @@ class PPCInstPrinter : public MCInstPrinter {
   Triple TT;
 private:
   bool showRegistersWithPercentPrefix(const char *RegName) const;
-  bool showRegistersWithPrefix() const;
+  bool showRegistersWithPrefix(const MCSubtargetInfo &STI) const;
   const char *getVerboseConditionRegName(unsigned RegNum,
-                                         unsigned RegEncoding) const;
+                                         unsigned RegEncoding,
+                                         const MCSubtargetInfo &STI) const;
 
 public:
   PPCInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
diff --git a/llvm/lib/Target/PowerPC/PPC.td b/llvm/lib/Target/PowerPC/PPC.td
index 535616d33a8032a..568a3d4b5a2aab1 100644
--- a/llvm/lib/Target/PowerPC/PPC.td
+++ b/llvm/lib/Target/PowerPC/PPC.td
@@ -338,6 +338,10 @@ def FeaturePredictableSelectIsExpensive :
 def FeatureFastMFLR : SubtargetFeature<"fast-MFLR", "HasFastMFLR", "true",
                                        "MFLR is a fast instruction">;
 
+def FeatureFullRegisterNames :
+  SubtargetFeature<"regnames", "FullRegisterNames", "true",
+                   "Use full register names in assembly.">;
+
 // Since new processors generally contain a superset of features of those that
 // came before them, the idea is to make implementations of new processors
 // less error prone and easier to read.
diff --git a/llvm/test/CodeGen/PowerPC/ppc-full-reg-names.ll b/llvm/test/CodeGen/PowerPC/ppc-full-reg-names.ll
new file mode 100644
index 000000000000000..cb0dcaf7566bcdd
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/ppc-full-reg-names.ll
@@ -0,0 +1,62 @@
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-linux-gnu < %s \
+; RUN: -mcpu=pwr8 -mattr=+regnames | FileCheck --check-prefix=FULLNAMES %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-gnu < %s \
+; RUN: -mcpu=pwr8 -mattr=+regnames | FileCheck --check-prefix=FULLNAMES %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-ibm-aix-xcoff < %s \
+; RUN: -mcpu=pwr8 -mattr=+regnames | FileCheck --check-prefix=FULLNAMES %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-linux-gnu < %s \
+; RUN: -mcpu=pwr8 -mattr=-regnames | FileCheck --check-prefix=NOFULLNAMES %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-gnu < %s \
+; RUN: -mcpu=pwr8 -mattr=-regnames | FileCheck --check-prefix=NOFULLNAMES %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-ibm-aix-xcoff < %s \
+; RUN: -mcpu=pwr8 -mattr=-regnames | FileCheck --check-prefix=NOFULLNAMES %s
+
+
+define dso_local signext i32 @IntNames(i32 noundef signext %a, i32 noundef signext %b) local_unnamed_addr #0 {
+; FULLNAMES-LABEL: IntNames:
+; FULLNAMES:       # %bb.0: # %entry
+; FULLNAMES-NEXT:    add r3, r4, r3
+; FULLNAMES-NEXT:    extsw r3, r3
+; FULLNAMES-NEXT:    blr
+;
+; NOFULLNAMES-LABEL: IntNames:
+; NOFULLNAMES:       # %bb.0: # %entry
+; NOFULLNAMES-NEXT:    add 3, 4, 3
+; NOFULLNAMES-NEXT:    extsw 3, 3
+; NOFULLNAMES-NEXT:    blr
+entry:
+  %add = add nsw i32 %b, %a
+  ret i32 %add
+}
+
+define dso_local double @FPNames(double noundef %a, double noundef %b) local_unnamed_addr #0 {
+; FULLNAMES-LABEL: FPNames:
+; FULLNAMES:       # %bb.0: # %entry
+; FULLNAMES-NEXT:    xsadddp f1, f1, f2
+; FULLNAMES-NEXT:    blr
+;
+; NOFULLNAMES-LABEL: FPNames:
+; NOFULLNAMES:       # %bb.0: # %entry
+; NOFULLNAMES-NEXT:    xsadddp 1, 1, 2
+; NOFULLNAMES-NEXT:    blr
+entry:
+  %add = fadd double %a, %b
+  ret double %add
+}
+
+define dso_local <4 x float> @VecNames(<4 x float> noundef %a, <4 x float> noundef %b) local_unnamed_addr #0 {
+; FULLNAMES-LABEL: VecNames:
+; FULLNAMES:       # %bb.0: # %entry
+; FULLNAMES-NEXT:    xvaddsp vs34, vs34, vs35
+; FULLNAMES-NEXT:    blr
+;
+; NOFULLNAMES-LABEL: VecNames:
+; NOFULLNAMES:       # %bb.0: # %entry
+; NOFULLNAMES-NEXT:    xvaddsp 34, 34, 35
+; NOFULLNAMES-NEXT:    blr
+entry:
+  %add = fadd <4 x float> %a, %b
+  ret <4 x float> %add
+}
+
+attributes #0 = { nounwind willreturn "target-features"="+altivec" }

>From 16d281607e0723904e31f6c58c3078d2798fa1d2 Mon Sep 17 00:00:00 2001
From: Stefan Pintilie <stefanp at ca.ibm.com>
Date: Wed, 25 Oct 2023 18:21:39 -0500
Subject: [PATCH 2/5] Missed a little cleanup on a couple of source files.

---
 llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp | 7 ++-----
 llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h   | 3 +--
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
index 17498627a84fdfd..bab3089aeb9892c 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
@@ -613,11 +613,8 @@ bool PPCInstPrinter::showRegistersWithPercentPrefix(const char *RegName) const {
 
 /// getVerboseConditionalRegName - This method expands the condition register
 /// when requested explicitly or targetting Darwin.
-const char *PPCInstPrinter::getVerboseConditionRegName(unsigned RegNum,
-                                                       unsigned RegEncoding,
-                                                       const MCSubtargetInfo &STI)
-                                                       const {
-                                                         // __SP__
+const char *PPCInstPrinter::getVerboseConditionRegName(
+    unsigned RegNum, unsigned RegEncoding, const MCSubtargetInfo &STI) const {
   if (!FullRegNames && !STI.hasFeature(PPC::FeatureFullRegisterNames))
     return nullptr;
   if (RegNum < PPC::CR0EQ || RegNum > PPC::CR7UN)
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h
index 2e29971a20fc593..a75ae3b400a2813 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h
@@ -23,8 +23,7 @@ class PPCInstPrinter : public MCInstPrinter {
 private:
   bool showRegistersWithPercentPrefix(const char *RegName) const;
   bool showRegistersWithPrefix(const MCSubtargetInfo &STI) const;
-  const char *getVerboseConditionRegName(unsigned RegNum,
-                                         unsigned RegEncoding,
+  const char *getVerboseConditionRegName(unsigned RegNum, unsigned RegEncoding,
                                          const MCSubtargetInfo &STI) const;
 
 public:

>From c62ee3fda4eb678cf31959a2da63e94405ed163b Mon Sep 17 00:00:00 2001
From: Stefan Pintilie <stefanp at ca.ibm.com>
Date: Wed, 1 Nov 2023 14:56:32 -0500
Subject: [PATCH 3/5] Changed the patch to use CodeGenOpts instead of target
 features.

I simplified the clang test significantly.
I also completely removed the llc test. Since the code gen opt is now internal
there is no good way that I know of to test it using llc.
---
 clang/include/clang/Basic/CodeGenOptions.def  |  1 +
 clang/include/clang/Driver/Options.td         | 10 ++-
 clang/lib/Basic/Targets/PPC.cpp               |  6 --
 clang/lib/Basic/Targets/PPC.h                 |  1 -
 clang/lib/CodeGen/BackendUtil.cpp             |  1 +
 clang/lib/Driver/ToolChains/Clang.cpp         |  6 ++
 clang/lib/Frontend/CompilerInvocation.cpp     |  3 +
 .../test/CodeGen/PowerPC/ppc-full-reg-names.c | 78 +++----------------
 llvm/include/llvm/MC/MCAsmInfo.h              |  6 ++
 llvm/include/llvm/MC/MCTargetOptions.h        |  3 +
 llvm/lib/CodeGen/LLVMTargetMachine.cpp        |  2 +
 llvm/lib/MC/MCAsmInfo.cpp                     |  1 +
 llvm/lib/MC/MCTargetOptions.cpp               |  2 +-
 .../PowerPC/MCTargetDesc/PPCInstPrinter.cpp   | 13 ++--
 .../PowerPC/MCTargetDesc/PPCInstPrinter.h     |  6 +-
 llvm/lib/Target/PowerPC/PPC.td                |  4 -
 .../CodeGen/PowerPC/ppc-full-reg-names.ll     | 62 ---------------
 17 files changed, 50 insertions(+), 155 deletions(-)
 delete mode 100644 llvm/test/CodeGen/PowerPC/ppc-full-reg-names.ll

diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def
index d7588fd430764cb..22658a01163261e 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -197,6 +197,7 @@ CODEGENOPT(HIPCorrectlyRoundedDivSqrt, 1, 1) ///< -fno-hip-fp32-correctly-rounde
 CODEGENOPT(HIPSaveKernelArgName, 1, 0) ///< Set when -fhip-kernel-arg-name is enabled.
 CODEGENOPT(UniqueInternalLinkageNames, 1, 0) ///< Internal Linkage symbols get unique names.
 CODEGENOPT(SplitMachineFunctions, 1, 0) ///< Split machine functions using profile information.
+CODEGENOPT(UseFullRegisterNames, 1, 0) ///< Print full register names in assembly -mregnames
 
 /// When false, this attempts to generate code as if the result of an
 /// overflowing conversion matches the overflowing behavior of a target's native
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 74b92b76bc2d866..4bf9597cde52b64 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4802,10 +4802,12 @@ def mrop_protect : Flag<["-"], "mrop-protect">,
     Group<m_ppc_Features_Group>;
 def mprivileged : Flag<["-"], "mprivileged">,
     Group<m_ppc_Features_Group>;
-def mregnames : Flag<["-"], "mregnames">, Group<m_ppc_Features_Group>,
-                Visibility<[ClangOption]>;
-def mno_regnames : Flag<["-"], "mno-regnames">, Group<m_ppc_Features_Group>,
-                   Visibility<[ClangOption]>;
+
+defm regnames : BoolOption<"m", "regnames",
+  CodeGenOpts<"UseFullRegisterNames">, DefaultFalse,
+  PosFlag<SetTrue, [], [ClangOption, CC1Option], "Use full register names when writing assembly output">,
+  NegFlag<SetFalse, [], [ClangOption], "Use only register numbers when writing assembly output">>,
+  Group<m_Group>;
 } // let Flags = [TargetSpecific]
 def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">,
   Group<m_ppc_Features_Group>,
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index fa8f598c1843461..0d87a3a4e8c20f3 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -89,8 +89,6 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
       IsISA3_1 = true;
     } else if (Feature == "+quadword-atomics") {
       HasQuadwordAtomics = true;
-    } else if (Feature == "+regnames") {
-      FullRegisterNames = true;
     }
     // TODO: Finish this list and add an assert that we've handled them
     // all.
@@ -549,9 +547,6 @@ bool PPCTargetInfo::initFeatureMap(
   // off by default.
   Features["aix-small-local-exec-tls"] = false;
 
-  // By default full register names are not used in assembly.
-  Features["regnames"] = false;
-
   Features["spe"] = llvm::StringSwitch<bool>(CPU)
                         .Case("8548", true)
                         .Case("e500", true)
@@ -701,7 +696,6 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
       .Case("isa-v30-instructions", IsISA3_0)
       .Case("isa-v31-instructions", IsISA3_1)
       .Case("quadword-atomics", HasQuadwordAtomics)
-      .Case("regnames", FullRegisterNames)
       .Default(false);
 }
 
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index ddef057bb306cad..4d62673ba7fb8c5 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -80,7 +80,6 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
   bool IsISA3_0 = false;
   bool IsISA3_1 = false;
   bool HasQuadwordAtomics = false;
-  bool FullRegisterNames = false;
 
 protected:
   std::string ABI;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 70accce456d3c07..34fbe127b8df3a2 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -488,6 +488,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Options.MCOptions.Argv0 = CodeGenOpts.Argv0;
   Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs;
   Options.MCOptions.AsSecureLogFile = CodeGenOpts.AsSecureLogFile;
+  Options.MCOptions.UseFullRegisterNames = CodeGenOpts.UseFullRegisterNames;
   Options.MisExpect = CodeGenOpts.MisExpect;
 
   return true;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..de7934e92ed2c96 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5011,6 +5011,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ);
   }
 
+  if (const Arg *A = Args.getLastArg(options::OPT_mregnames,
+                                     options::OPT_mno_regnames)) {
+    if (A->getOption().matches(options::OPT_mregnames))
+      Args.AddLastArg(CmdArgs, options::OPT_mregnames);
+  }
+
   if (Args.getLastArg(options::OPT_fthin_link_bitcode_EQ))
     Args.AddLastArg(CmdArgs, options::OPT_fthin_link_bitcode_EQ);
 
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 4e6d7bb16f51beb..6a6222d1f5c7793 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1773,6 +1773,9 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
       Opts.setDebugInfo(llvm::codegenoptions::LimitedDebugInfo);
   }
 
+  if (const Arg *A = Args.getLastArg(OPT_mregnames))
+    Opts.UseFullRegisterNames = true;
+
   for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ)) {
     auto Split = StringRef(Arg).split('=');
     Opts.DebugPrefixMap.emplace_back(Split.first, Split.second);
diff --git a/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c b/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
index c1bd22c1134c9a7..aaf722213dc4a07 100644
--- a/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
+++ b/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
@@ -1,78 +1,20 @@
 // REQUIRES: powerpc-registered-target
-// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mregnames \
+// RUN: %clang -### -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -mregnames \
 // RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
-// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mregnames \
+// RUN: %clang -### -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -mregnames \
 // RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
-// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -emit-llvm -mregnames \
+// RUN: %clang -### -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -mregnames \
 // RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
-// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mno-regnames \
+// RUN: %clang -### -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -mno-regnames \
 // RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
-// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm -mno-regnames \
+// RUN: %clang -### -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -mno-regnames \
 // RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
-// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -emit-llvm -mno-regnames \
+// RUN: %clang -### -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -mno-regnames \
 // RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
 
-// Also check the assembly to make sure that the full names are used.
-// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mregnames \
-// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMFULLNAMES
-// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mregnames \
-// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMFULLNAMES
-// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -mregnames \
-// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMFULLNAMES
-// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mno-regnames \
-// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMNOFULLNAMES
-// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mno-regnames \
-// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMNOFULLNAMES
-// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S -mno-regnames \
-// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMNOFULLNAMES
-
-
-
-// FULLNAMES-LABEL: @IntNames
-// FULLNAMES-SAME:  #0
-// NOFULLNAMES-LABEL: @IntNames
-// NOFULLNAMES-SAME:  #0
-// ASMFULLNAMES-LABEL: IntNames:
-// ASMFULLNAMES:         add r3, r4, r3
-// ASMFULLNAMES:         blr
-// ASMNOFULLNAMES-LABEL: IntNames:
-// ASMNOFULLNAMES:         add 3, 4, 3
-// ASMNOFULLNAMES:         blr
-int IntNames(int a, int b) {
-  return a + b;
-}
-
-// FULLNAMES-LABEL: @FPNames
-// FULLNAMES-SAME:  #0
-// NOFULLNAMES-LABEL: @FPNames
-// NOFULLNAMES-SAME:  #0
-// ASMFULLNAMES-LABEL: FPNames:
-// ASMFULLNAMES:         xsadddp f1, f1, f2
-// ASMFULLNAMES:         blr
-// ASMNOFULLNAMES-LABEL: FPNames:
-// ASMNOFULLNAMES:         xsadddp 1, 1, 2
-// ASMNOFULLNAMES:         blr
-double FPNames(double a, double b) {
-  return a + b;
-}
-
-// FULLNAMES-LABEL: @VecNames
-// FULLNAMES-SAME:  #0
-// NOFULLNAMES-LABEL: @VecNames
-// NOFULLNAMES-SAME:  #0
-// ASMFULLNAMES-LABEL: VecNames:
-// ASMFULLNAMES:         xvaddsp vs34, vs34, vs35
-// ASMFULLNAMES:         blr
-// ASMNOFULLNAMES-LABEL: VecNames:
-// ASMNOFULLNAMES:         xvaddsp 34, 34, 35
-// ASMNOFULLNAMES:         blr
-vector float VecNames(vector float a, vector float b) {
-  return a + b;
-}
-
-// FULLNAMES: attributes #0 = {
-// FULLNAMES-SAME: +regnames
-// NOFULLNAMES: attributes #0 = {
-// NOFULLNAMES-SAME: -regnames
+// FULLNAMES: clang
+// FULLNAMES-SAME: -mregnames
+// NOFULLNAMES: clang
+// NOFULLNAMES-SAME-NOT: -mregnames
 
 
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index c28cd12112358c7..4ac0eb89d850407 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -240,6 +240,9 @@ class MCAsmInfo {
   /// True if the target supports LEB128 directives.
   bool HasLEB128Directives = true;
 
+  /// True if full register names are printed.
+  bool UseFullRegisterNames = false;
+
   //===--- Data Emission Directives -------------------------------------===//
 
   /// This should be set to the directive used to get some number of zero (and
@@ -710,6 +713,9 @@ class MCAsmInfo {
 
   bool hasLEB128Directives() const { return HasLEB128Directives; }
 
+  bool useFullRegisterNames() const { return UseFullRegisterNames; }
+  void setFullRegisterNames(bool V) { UseFullRegisterNames = V; }
+
   const char *getZeroDirective() const { return ZeroDirective; }
   bool doesZeroDirectiveSupportNonZeroValue() const {
     return ZeroDirectiveSupportsNonZeroValue;
diff --git a/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h
index 9fc1e07d085ebaa..e2d18041c3baa13 100644
--- a/llvm/include/llvm/MC/MCTargetOptions.h
+++ b/llvm/include/llvm/MC/MCTargetOptions.h
@@ -89,6 +89,9 @@ class MCTargetOptions {
   // functions on Darwins.
   bool EmitCompactUnwindNonCanonical : 1;
 
+  // Whether or not to use full register names on PowerPC.
+  bool UseFullRegisterNames : 1;
+
   MCTargetOptions();
 
   /// getABIName - If this returns a non-empty string this represents the
diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index 87a17b88db12433..4f4566b8add170a 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -81,6 +81,8 @@ void LLVMTargetMachine::initAsmInfo() {
 
   TmpAsmInfo->setRelaxELFRelocations(Options.RelaxELFRelocations);
 
+  TmpAsmInfo->setFullRegisterNames(Options.MCOptions.UseFullRegisterNames);
+
   if (Options.ExceptionModel != ExceptionHandling::None)
     TmpAsmInfo->setExceptionsType(Options.ExceptionModel);
 
diff --git a/llvm/lib/MC/MCAsmInfo.cpp b/llvm/lib/MC/MCAsmInfo.cpp
index 1675e24301dc69c..e4ace2de864d6b5 100644
--- a/llvm/lib/MC/MCAsmInfo.cpp
+++ b/llvm/lib/MC/MCAsmInfo.cpp
@@ -67,6 +67,7 @@ MCAsmInfo::MCAsmInfo() {
   UseIntegratedAssembler = true;
   ParseInlineAsmUsingAsmParser = false;
   PreserveAsmComments = true;
+  UseFullRegisterNames = false;
 }
 
 MCAsmInfo::~MCAsmInfo() = default;
diff --git a/llvm/lib/MC/MCTargetOptions.cpp b/llvm/lib/MC/MCTargetOptions.cpp
index 8fea8c7715bdc81..6dc280176cd51cc 100644
--- a/llvm/lib/MC/MCTargetOptions.cpp
+++ b/llvm/lib/MC/MCTargetOptions.cpp
@@ -19,7 +19,7 @@ MCTargetOptions::MCTargetOptions()
       PreserveAsmComments(true), Dwarf64(false),
       EmitDwarfUnwind(EmitDwarfUnwindType::Default),
       MCUseDwarfDirectory(DefaultDwarfDirectory),
-      EmitCompactUnwindNonCanonical(false) {}
+      EmitCompactUnwindNonCanonical(false), UseFullRegisterNames(false) {}
 
 StringRef MCTargetOptions::getABIName() const {
   return ABIName;
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
index bab3089aeb9892c..ea9721c9159d4a2 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
@@ -13,6 +13,7 @@
 #include "MCTargetDesc/PPCInstPrinter.h"
 #include "MCTargetDesc/PPCMCTargetDesc.h"
 #include "MCTargetDesc/PPCPredicates.h"
+#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCInstrInfo.h"
@@ -614,8 +615,8 @@ bool PPCInstPrinter::showRegistersWithPercentPrefix(const char *RegName) const {
 /// getVerboseConditionalRegName - This method expands the condition register
 /// when requested explicitly or targetting Darwin.
 const char *PPCInstPrinter::getVerboseConditionRegName(
-    unsigned RegNum, unsigned RegEncoding, const MCSubtargetInfo &STI) const {
-  if (!FullRegNames && !STI.hasFeature(PPC::FeatureFullRegisterNames))
+    unsigned RegNum, unsigned RegEncoding) const {
+  if (!FullRegNames && !MAI.useFullRegisterNames())
     return nullptr;
   if (RegNum < PPC::CR0EQ || RegNum > PPC::CR7UN)
     return nullptr;
@@ -634,9 +635,9 @@ const char *PPCInstPrinter::getVerboseConditionRegName(
 
 // showRegistersWithPrefix - This method determines whether registers
 // should be number-only or include the prefix.
-bool PPCInstPrinter::showRegistersWithPrefix(const MCSubtargetInfo &STI) const {
+bool PPCInstPrinter::showRegistersWithPrefix() const {
   return FullRegNamesWithPercent || FullRegNames ||
-         STI.hasFeature(PPC::FeatureFullRegisterNames);
+         MAI.useFullRegisterNames();
 }
 
 void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
@@ -648,12 +649,12 @@ void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
       Reg = PPC::getRegNumForOperand(MII.get(MI->getOpcode()), Reg, OpNo);
 
     const char *RegName;
-    RegName = getVerboseConditionRegName(Reg, MRI.getEncodingValue(Reg), STI);
+    RegName = getVerboseConditionRegName(Reg, MRI.getEncodingValue(Reg));
     if (RegName == nullptr)
      RegName = getRegisterName(Reg);
     if (showRegistersWithPercentPrefix(RegName))
       O << "%";
-    if (!showRegistersWithPrefix(STI))
+    if (!showRegistersWithPrefix())
       RegName = PPC::stripRegisterPrefix(RegName);
 
     O << RegName;
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h
index a75ae3b400a2813..6ba3eb4c79dc990 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h
@@ -22,9 +22,9 @@ class PPCInstPrinter : public MCInstPrinter {
   Triple TT;
 private:
   bool showRegistersWithPercentPrefix(const char *RegName) const;
-  bool showRegistersWithPrefix(const MCSubtargetInfo &STI) const;
-  const char *getVerboseConditionRegName(unsigned RegNum, unsigned RegEncoding,
-                                         const MCSubtargetInfo &STI) const;
+  bool showRegistersWithPrefix() const;
+  const char *getVerboseConditionRegName(unsigned RegNum,
+                                         unsigned RegEncoding) const;
 
 public:
   PPCInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
diff --git a/llvm/lib/Target/PowerPC/PPC.td b/llvm/lib/Target/PowerPC/PPC.td
index 568a3d4b5a2aab1..535616d33a8032a 100644
--- a/llvm/lib/Target/PowerPC/PPC.td
+++ b/llvm/lib/Target/PowerPC/PPC.td
@@ -338,10 +338,6 @@ def FeaturePredictableSelectIsExpensive :
 def FeatureFastMFLR : SubtargetFeature<"fast-MFLR", "HasFastMFLR", "true",
                                        "MFLR is a fast instruction">;
 
-def FeatureFullRegisterNames :
-  SubtargetFeature<"regnames", "FullRegisterNames", "true",
-                   "Use full register names in assembly.">;
-
 // Since new processors generally contain a superset of features of those that
 // came before them, the idea is to make implementations of new processors
 // less error prone and easier to read.
diff --git a/llvm/test/CodeGen/PowerPC/ppc-full-reg-names.ll b/llvm/test/CodeGen/PowerPC/ppc-full-reg-names.ll
deleted file mode 100644
index cb0dcaf7566bcdd..000000000000000
--- a/llvm/test/CodeGen/PowerPC/ppc-full-reg-names.ll
+++ /dev/null
@@ -1,62 +0,0 @@
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-linux-gnu < %s \
-; RUN: -mcpu=pwr8 -mattr=+regnames | FileCheck --check-prefix=FULLNAMES %s
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-gnu < %s \
-; RUN: -mcpu=pwr8 -mattr=+regnames | FileCheck --check-prefix=FULLNAMES %s
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-ibm-aix-xcoff < %s \
-; RUN: -mcpu=pwr8 -mattr=+regnames | FileCheck --check-prefix=FULLNAMES %s
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-linux-gnu < %s \
-; RUN: -mcpu=pwr8 -mattr=-regnames | FileCheck --check-prefix=NOFULLNAMES %s
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-gnu < %s \
-; RUN: -mcpu=pwr8 -mattr=-regnames | FileCheck --check-prefix=NOFULLNAMES %s
-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-ibm-aix-xcoff < %s \
-; RUN: -mcpu=pwr8 -mattr=-regnames | FileCheck --check-prefix=NOFULLNAMES %s
-
-
-define dso_local signext i32 @IntNames(i32 noundef signext %a, i32 noundef signext %b) local_unnamed_addr #0 {
-; FULLNAMES-LABEL: IntNames:
-; FULLNAMES:       # %bb.0: # %entry
-; FULLNAMES-NEXT:    add r3, r4, r3
-; FULLNAMES-NEXT:    extsw r3, r3
-; FULLNAMES-NEXT:    blr
-;
-; NOFULLNAMES-LABEL: IntNames:
-; NOFULLNAMES:       # %bb.0: # %entry
-; NOFULLNAMES-NEXT:    add 3, 4, 3
-; NOFULLNAMES-NEXT:    extsw 3, 3
-; NOFULLNAMES-NEXT:    blr
-entry:
-  %add = add nsw i32 %b, %a
-  ret i32 %add
-}
-
-define dso_local double @FPNames(double noundef %a, double noundef %b) local_unnamed_addr #0 {
-; FULLNAMES-LABEL: FPNames:
-; FULLNAMES:       # %bb.0: # %entry
-; FULLNAMES-NEXT:    xsadddp f1, f1, f2
-; FULLNAMES-NEXT:    blr
-;
-; NOFULLNAMES-LABEL: FPNames:
-; NOFULLNAMES:       # %bb.0: # %entry
-; NOFULLNAMES-NEXT:    xsadddp 1, 1, 2
-; NOFULLNAMES-NEXT:    blr
-entry:
-  %add = fadd double %a, %b
-  ret double %add
-}
-
-define dso_local <4 x float> @VecNames(<4 x float> noundef %a, <4 x float> noundef %b) local_unnamed_addr #0 {
-; FULLNAMES-LABEL: VecNames:
-; FULLNAMES:       # %bb.0: # %entry
-; FULLNAMES-NEXT:    xvaddsp vs34, vs34, vs35
-; FULLNAMES-NEXT:    blr
-;
-; NOFULLNAMES-LABEL: VecNames:
-; NOFULLNAMES:       # %bb.0: # %entry
-; NOFULLNAMES-NEXT:    xvaddsp 34, 34, 35
-; NOFULLNAMES-NEXT:    blr
-entry:
-  %add = fadd <4 x float> %a, %b
-  ret <4 x float> %add
-}
-
-attributes #0 = { nounwind willreturn "target-features"="+altivec" }

>From b74c03fed306dde1beec3821f400ad8f7b505d29 Mon Sep 17 00:00:00 2001
From: Stefan Pintilie <stefanp at ca.ibm.com>
Date: Wed, 1 Nov 2023 15:07:26 -0500
Subject: [PATCH 4/5] Fixed the broken test case.

---
 .../test/CodeGen/PowerPC/ppc-full-reg-names.c  | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c b/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
index aaf722213dc4a07..aac15d7ae922945 100644
--- a/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
+++ b/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
@@ -1,20 +1,18 @@
 // REQUIRES: powerpc-registered-target
 // RUN: %clang -### -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -mregnames \
-// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=FULLNAMES
 // RUN: %clang -### -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -mregnames \
-// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=FULLNAMES
 // RUN: %clang -### -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -mregnames \
-// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=FULLNAMES
 // RUN: %clang -### -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -mno-regnames \
-// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NOFULLNAMES
 // RUN: %clang -### -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -mno-regnames \
-// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NOFULLNAMES
 // RUN: %clang -### -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -mno-regnames \
-// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN:   %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NOFULLNAMES
 
-// FULLNAMES: clang
-// FULLNAMES-SAME: -mregnames
-// NOFULLNAMES: clang
-// NOFULLNAMES-SAME-NOT: -mregnames
+// FULLNAMES: -mregnames
+// NOFULLNAMES-NOT: -mregnames
 
 

>From a27bf30131550a2e62e64b19fd06a9d67a73e340 Mon Sep 17 00:00:00 2001
From: Stefan Pintilie <stefanp at ca.ibm.com>
Date: Wed, 1 Nov 2023 20:48:58 -0500
Subject: [PATCH 5/5] Fixed the formatting.

---
 clang/lib/Driver/ToolChains/Clang.cpp                   | 4 ++--
 llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index de7934e92ed2c96..a65400348db8c39 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5011,8 +5011,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ);
   }
 
-  if (const Arg *A = Args.getLastArg(options::OPT_mregnames,
-                                     options::OPT_mno_regnames)) {
+  if (const Arg *A =
+          Args.getLastArg(options::OPT_mregnames, options::OPT_mno_regnames)) {
     if (A->getOption().matches(options::OPT_mregnames))
       Args.AddLastArg(CmdArgs, options::OPT_mregnames);
   }
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
index ea9721c9159d4a2..b0a060e1e224a48 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
@@ -614,8 +614,9 @@ bool PPCInstPrinter::showRegistersWithPercentPrefix(const char *RegName) const {
 
 /// getVerboseConditionalRegName - This method expands the condition register
 /// when requested explicitly or targetting Darwin.
-const char *PPCInstPrinter::getVerboseConditionRegName(
-    unsigned RegNum, unsigned RegEncoding) const {
+const char *
+PPCInstPrinter::getVerboseConditionRegName(unsigned RegNum,
+                                           unsigned RegEncoding) const {
   if (!FullRegNames && !MAI.useFullRegisterNames())
     return nullptr;
   if (RegNum < PPC::CR0EQ || RegNum > PPC::CR7UN)
@@ -636,8 +637,7 @@ const char *PPCInstPrinter::getVerboseConditionRegName(
 // showRegistersWithPrefix - This method determines whether registers
 // should be number-only or include the prefix.
 bool PPCInstPrinter::showRegistersWithPrefix() const {
-  return FullRegNamesWithPercent || FullRegNames ||
-         MAI.useFullRegisterNames();
+  return FullRegNamesWithPercent || FullRegNames || MAI.useFullRegisterNames();
 }
 
 void PPCInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,



More information about the cfe-commits mailing list