[llvm] 29456e9 - [PowerPC] Fix assembler error with toc-data and data-sections (#91976)

via llvm-commits llvm-commits at lists.llvm.org
Wed May 22 11:07:56 PDT 2024


Author: Zaara Syeda
Date: 2024-05-22T14:07:51-04:00
New Revision: 29456e9bcc478d458f40a93d309f992f0a314523

URL: https://github.com/llvm/llvm-project/commit/29456e9bcc478d458f40a93d309f992f0a314523
DIFF: https://github.com/llvm/llvm-project/commit/29456e9bcc478d458f40a93d309f992f0a314523.diff

LOG: [PowerPC] Fix assembler error with toc-data and data-sections (#91976)

We should not emit the label for the toc-data variable when
data-sections=false.

Added: 
    llvm/test/CodeGen/PowerPC/toc-data-no-data-sections.ll

Modified: 
    llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 72e8215fffaf7..f4e84ade3b5ac 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -2831,8 +2831,10 @@ void PPCAIXAsmPrinter::emitGlobalVariableHelper(const GlobalVariable *GV) {
 
   // When -fdata-sections is enabled, every GlobalVariable will
   // be put into its own csect; therefore, label is not necessary here.
-  if (!TM.getDataSections() || GV->hasSection())
-    OutStreamer->emitLabel(EmittedInitSym);
+  if (!TM.getDataSections() || GV->hasSection()) {
+    if (Csect->getMappingClass() != XCOFF::XMC_TD)
+      OutStreamer->emitLabel(EmittedInitSym);
+  }
 
   // No alias to emit.
   if (!GOAliasMap[GV].size()) {

diff  --git a/llvm/test/CodeGen/PowerPC/toc-data-no-data-sections.ll b/llvm/test/CodeGen/PowerPC/toc-data-no-data-sections.ll
new file mode 100644
index 0000000000000..77851fb830253
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/toc-data-no-data-sections.ll
@@ -0,0 +1,18 @@
+; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -data-sections=false -verify-machineinstrs < %s | FileCheck %s
+
+ at a1 = global i32 0, align 4 #0
+
+define void @foo() {
+entry:
+  store i32 1, ptr @a1, align 4
+  ret void
+}
+
+attributes #0 = { "toc-data" }
+
+; CHECK: .toc
+; CHECK-NEXT: .csect a1[TD],2
+; CHECK-NEXT: .globl  a1[TD]
+; CHECK-NEXT: .align  2
+; CHECK-NOT: a1[TD]:
+; CHECK-NEXT: .vbyte  4, 0


        


More information about the llvm-commits mailing list