diff --git a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp --- a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp @@ -7370,6 +7370,8 @@ case PPC::ADDItocL: Flags = PPCII::MO_TOC_LO; break; + case PPC::ADDItoc: + break; } SDValue ImmOpnd = Base.getOperand(1); @@ -7465,11 +7467,20 @@ } if (FirstOp == 1) // Store - (void)CurDAG->UpdateNodeOperands(N, N->getOperand(0), ImmOpnd, - Base.getOperand(0), N->getOperand(3)); + if (Base.getMachineOpcode() == PPC::ADDItoc) + (void)CurDAG->UpdateNodeOperands(N, N->getOperand(0), + Base.getOperand(0), Base.getOperand(1), + N->getOperand(3)); + else + (void)CurDAG->UpdateNodeOperands(N, N->getOperand(0), ImmOpnd, + Base.getOperand(0), N->getOperand(3)); else // Load - (void)CurDAG->UpdateNodeOperands(N, ImmOpnd, Base.getOperand(0), - N->getOperand(2)); + if (Base.getMachineOpcode() == PPC::ADDItoc) + (void)CurDAG->UpdateNodeOperands(N, Base.getOperand(0), + Base.getOperand(1), N->getOperand(2)); + else + (void)CurDAG->UpdateNodeOperands(N, ImmOpnd, Base.getOperand(0), + N->getOperand(2)); if (UpdateHBase) (void)CurDAG->UpdateNodeOperands(HBase.getNode(), HBase.getOperand(0), diff --git a/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp b/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp --- a/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp +++ b/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp @@ -42,6 +42,11 @@ Mangler::getNameWithPrefix(Name, MO.getSymbolName(), DL); } else { const GlobalValue *GV = MO.getGlobal(); + + if (const GlobalVariable *GVar = dyn_cast(GV)) + if (GVar->hasAttribute("toc-data")) + return AP.getSymbol(GV); + TM.getNameWithPrefix(Name, GV, Mang); } diff --git a/llvm/test/CodeGen/PowerPC/toc-data-const.ll b/llvm/test/CodeGen/PowerPC/toc-data-const.ll --- a/llvm/test/CodeGen/PowerPC/toc-data-const.ll +++ b/llvm/test/CodeGen/PowerPC/toc-data-const.ll @@ -1,5 +1,8 @@ -; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s --check-prefix CHECK -; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s --check-prefix CHECK +; RUN: llc -O0 -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s --check-prefixes=CHECK,NOOPT +; RUN: llc -O0 -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s --check-prefixes=CHECK,NOOPT + +; RUN llc -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s --check-prefix=CHECK,OPT +; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s --check-prefixes=CHECK,NOOPT @i1 = external constant i32 #0 @i2 = constant i32* @i1 #0 @@ -13,11 +16,13 @@ ret i32** @i2 } -; CHECK: .read: -; CHECK: la 3, i1[TD](2) +; CHECK-LABEL: .read: +; NOOPT: la 3, i1[TD](2) +; NOOPT: lwz 3, 0(3) +; OPT: lwz 3, i1[TD](2) -; CHECK: .retptr: -; CHECK: la 3, i2[TD](2) +; CHECK-LABEL: .retptr: +; CHECK: la 3, i2[TD](2) ; CHECK-DAG: .toc ; CHECK: .extern i1[TD] diff --git a/llvm/test/CodeGen/PowerPC/toc-data.ll b/llvm/test/CodeGen/PowerPC/toc-data.ll --- a/llvm/test/CodeGen/PowerPC/toc-data.ll +++ b/llvm/test/CodeGen/PowerPC/toc-data.ll @@ -1,15 +1,15 @@ ; RUN: llc -mtriple powerpc-ibm-aix-xcoff -verify-machineinstrs < %s \ -; RUN: -stop-before=ppc-vsx-copy | FileCheck %s --check-prefix CHECK32 +; RUN: -stop-before=ppc-vsx-copy | FileCheck %s --check-prefixes=CHECK32,OPT32 ; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -verify-machineinstrs < %s \ ; RUN: -stop-before=ppc-vsx-copy | FileCheck %s --check-prefix CHECK64 -; RUN: llc -mtriple powerpc-ibm-aix-xcoff -verify-machineinstrs < %s | FileCheck %s --check-prefix TEST32 +; RUN: llc -mtriple powerpc-ibm-aix-xcoff -verify-machineinstrs < %s | FileCheck %s --check-prefixes=TEST32,ASMOPT32 ; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -verify-machineinstrs < %s | FileCheck %s --check-prefix TEST64 ; RUN: llc -mtriple powerpc-ibm-aix-xcoff -verify-machineinstrs < %s \ -; RUN: -stop-before=ppc-vsx-copy -O0 | FileCheck %s --check-prefix CHECK32 +; RUN: -stop-before=ppc-vsx-copy -O0 | FileCheck %s --check-prefixes=CHECK32,NOOPT32 ; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -verify-machineinstrs < %s \ ; RUN: -stop-before=ppc-vsx-copy -O0 | FileCheck %s --check-prefix CHECK64-NOOPT -; RUN: llc -mtriple powerpc-ibm-aix-xcoff -verify-machineinstrs -O0 < %s | FileCheck %s --check-prefix TEST32 +; RUN: llc -mtriple powerpc-ibm-aix-xcoff -verify-machineinstrs -O0 < %s | FileCheck %s --check-prefixes=TEST32,ASMNOOPT32 ; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -verify-machineinstrs -O0 < %s | FileCheck %s --check-prefix TEST64 @i = dso_local global i32 0, align 4 #0 @@ -24,12 +24,14 @@ ret void } ; CHECK32: name: write_int -; CHECK32: %[[SCRATCH:[0-9]+]]:gprc_and_gprc_nor0 = ADDItoc @i, $r2 -; CHECK32-NEXT: STW %{{[0-9]+}}, 0, killed %[[SCRATCH]] :: (store (s32) into @i) +; NOOPT32: %[[SCRATCH:[0-9]+]]:gprc_and_gprc_nor0 = ADDItoc @i, $r2 +; NOOPT32-NEXT: STW %{{[0-9]+}}, 0, killed %[[SCRATCH]] :: (store (s32) into @i) +; OPT32: STW %{{[0-9]+}}, @i, $r2 :: (store (s32) into @i) -; TEST32: .write_int: -; TEST32: la 4, i[TD](2) -; TEST32-NEXT: stw 3, 0(4) +; TEST32: .write_int: +; ASMNOOPT32: la 4, i[TD](2) +; ASMNOOPT32-NEXT: stw 3, 0(4) +; ASMOPT32: stw 3, i[TD](2) ; CHECK64: name: write_int ; CHECK64: %[[SCRATCH:[0-9]+]]:g8rc_and_g8rc_nox0 = ADDItoc8 @i, $x2 @@ -77,12 +79,14 @@ ret float %0 } ; CHECK32: name: read_float -; CHECK32: %[[SCRATCH:[0-9]+]]:gprc_and_gprc_nor0 = ADDItoc @f, $r2 -; CHECK32: %{{[0-9]+}}:f4rc = LFS 0, killed %[[SCRATCH]] :: (dereferenceable load (s32) from @f) - -; TEST32: .read_float: -; TEST32: la 3, f[TD](2) -; TEST32-NEXT: lfs 1, 0(3) +; NOOPT32: %[[SCRATCH:[0-9]+]]:gprc_and_gprc_nor0 = ADDItoc @f, $r2 +; NOOPT32: %{{[0-9]+}}:f4rc = LFS 0, killed %[[SCRATCH]] :: (dereferenceable load (s32) from @f) +; OPT32: %{{[0-9]+}}:f4rc = LFS @f, $r2 :: (dereferenceable load (s32) from @f) + +; TEST32: .read_float: +; ASMNOOPT32: la 3, f[TD](2) +; ASMNOOPT32-NEXT: lfs 1, 0(3) +; ASMOPT32: lfs 1, f[TD](2) ; CHECK64: name: read_float ; CHECK64: %[[SCRATCH:[0-9]+]]:g8rc_and_g8rc_nox0 = ADDItoc8 @f, $x2