Skip to content

Commit 10d3bf9

Browse files
committed
[PowerPC][AIX] Fallback to DAG-ISEL if global has toc-data attribute.
FAST-ISEL should fall back to DAG-ISEL when a global variable has the toc-data attribute. A number of the checks were duplicated in the lit test becuase of 1) Slightly different output between -O0 and -O2 due to FAST-ISEL vs DAG-ISEL codegen. 2) In preperation of a peephole optimization that will run when optimizations are enabled. Differential Revision: https://reviews.llvm.org/D115373
1 parent 964dc36 commit 10d3bf9

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

llvm/lib/Target/PowerPC/PPCFastISel.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,12 @@ unsigned PPCFastISel::PPCMaterializeGV(const GlobalValue *GV, MVT VT) {
20742074
if (GV->isThreadLocal())
20752075
return 0;
20762076

2077+
// If the global has the toc-data attribute then fallback to DAG-ISEL.
2078+
if (TM.getTargetTriple().isOSAIX())
2079+
if (const GlobalVariable *Var = dyn_cast_or_null<GlobalVariable>(GV))
2080+
if (Var->hasAttribute("toc-data"))
2081+
return false;
2082+
20772083
PPCFuncInfo->setUsesTOCBasePtr();
20782084
// For small code model, generate a simple TOC load.
20792085
if (CModel == CodeModel::Small)

llvm/test/CodeGen/PowerPC/toc-data.ll

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
; REQUIRES: asserts
21
; RUN: llc -mtriple powerpc-ibm-aix-xcoff -verify-machineinstrs < %s \
3-
; RUN: -stop-before=ppc-ctr-loops-verify | FileCheck %s --check-prefix CHECK32
2+
; RUN: -stop-before=ppc-vsx-copy | FileCheck %s --check-prefix CHECK32
43
; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -verify-machineinstrs < %s \
5-
; RUN: -stop-before=ppc-ctr-loops-verify | FileCheck %s --check-prefix CHECK64
4+
; RUN: -stop-before=ppc-vsx-copy | FileCheck %s --check-prefix CHECK64
65
; RUN: llc -mtriple powerpc-ibm-aix-xcoff -verify-machineinstrs < %s | FileCheck %s --check-prefix TEST32
76
; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -verify-machineinstrs < %s | FileCheck %s --check-prefix TEST64
87

8+
; RUN: llc -mtriple powerpc-ibm-aix-xcoff -verify-machineinstrs < %s \
9+
; RUN: -stop-before=ppc-vsx-copy -O0 | FileCheck %s --check-prefix CHECK32
10+
; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -verify-machineinstrs < %s \
11+
; RUN: -stop-before=ppc-vsx-copy -O0 | FileCheck %s --check-prefix CHECK64-NOOPT
12+
; RUN: llc -mtriple powerpc-ibm-aix-xcoff -verify-machineinstrs -O0 < %s | FileCheck %s --check-prefix TEST32
13+
; RUN: llc -mtriple powerpc64-ibm-aix-xcoff -verify-machineinstrs -O0 < %s | FileCheck %s --check-prefix TEST64
14+
915
@i = dso_local global i32 0, align 4 #0
1016
@d = dso_local local_unnamed_addr global double 3.141590e+00, align 8
1117
@f = dso_local local_unnamed_addr global float 0x4005BE76C0000000, align 4 #0
@@ -29,6 +35,11 @@ define dso_local void @write_int(i32 signext %in) {
2935
; CHECK64: %[[SCRATCH:[0-9]+]]:g8rc_and_g8rc_nox0 = ADDItoc8 @i, $x2
3036
; CHECK64-NEXT: STW8 %{{[0-9]+}}, 0, killed %[[SCRATCH]] :: (store (s32) into @i)
3137

38+
; CHECK64-NOOPT: name: write_int
39+
; CHECK64-NOOPT: %[[SUBREG:[0-9]+]]:gprc = COPY %{{[0-9]}}.sub_32
40+
; CHECK64-NOOPT: %[[ADDR:[0-9]+]]:g8rc_and_g8rc_nox0 = ADDItoc8 @i, $x2 :: (load (s64) from got)
41+
; CHECK64-NOOPT: STW %[[SUBREG]], 0, killed %[[ADDR]] :: (store (s32) into @i)
42+
3243
; TEST64: .write_int:
3344
; TEST64: la 4, i[TD](2)
3445
; TEST64-NEXT: stw 3, 0(4)
@@ -48,7 +59,12 @@ define dso_local i64 @read_ll() {
4859
; TEST32-NEXT: lwz 4, 4(4)
4960

5061
; CHECK64: name: read_ll
51-
; CHECK64: LDtoc @ll, $x2 :: (load (s64) from got)
62+
; CHECK64: %[[SCRATCH:[0-9]+]]:g8rc_and_g8rc_nox0 = LDtoc @ll, $x2 :: (load (s64) from got)
63+
; CHECK64: LD 0, killed %[[SCRATCH]]
64+
65+
; CHECK64-NOOPT: name: read_ll
66+
; CHECK64-NOOPT: %[[SCRATCH:[0-9]+]]:g8rc_and_g8rc_nox0 = LDtoc @ll, $x2
67+
; CHECK64-NOOPT: LD 0, %[[SCRATCH]]
5268

5369
; TEST64: .read_ll:
5470
; TEST64: ld 3, L..C0(2)
@@ -72,6 +88,10 @@ define dso_local float @read_float() {
7288
; CHECK64: %[[SCRATCH:[0-9]+]]:g8rc_and_g8rc_nox0 = ADDItoc8 @f, $x2
7389
; CHECK64: %{{[0-9]+}}:f4rc = LFS 0, killed %[[SCRATCH]] :: (dereferenceable load (s32) from @f)
7490

91+
; CHECK64-NOOPT: name: read_float
92+
; CHECK64-NOOPT: %[[SCRATCH:[0-9]+]]:g8rc_and_g8rc_nox0 = ADDItoc8 @f, $x2
93+
; CHECK64-NOOPT: %{{[0-9]+}}:f4rc = LFS 0, killed %[[SCRATCH]]
94+
7595
; TEST64: .read_float:
7696
; TEST64: la 3, f[TD](2)
7797
; TEST64-NEXT: lfs 1, 0(3)
@@ -90,7 +110,12 @@ define dso_local void @write_double(double %in) {
90110
; TEST32-NEXT: stfd 1, 0(3)
91111

92112
; CHECK64: name: write_double
93-
; CHECK64: LDtoc @d, $x2 :: (load (s64) from got)
113+
; CHECK64: %[[SCRATCH:[0-9]+]]:g8rc_and_g8rc_nox0 = LDtoc @d, $x2 :: (load (s64) from got)
114+
; CHECK64: STFD %{{[0-9]+}}, 0, killed %[[SCRATCH]]
115+
116+
; CHECK64-NOOPT: name: write_double
117+
; CHECK64-NOOPT: %[[SCRATCH:[0-9]+]]:g8rc_and_g8rc_nox0 = LDtoc @d, $x2
118+
; CHECK64-NOOPT STFD %{{[0-9]+}}, 0 %[[SCRATCH]]
94119

95120
; TEST64: .write_double
96121
; TEST64: ld 3, L..C1(2)
@@ -112,6 +137,10 @@ define dso_local nonnull i32* @addr() {
112137
; CHECK64: %[[SCRATCH:[0-9]+]]:g8rc = ADDItoc8 @i, $x2
113138
; CHECK64-NEXT: $x3 = COPY %[[SCRATCH]]
114139

140+
; CHECK64-NOOPT: name: addr
141+
; CHECK64-NOOPT: %[[SCRATCH:[0-9]+]]:g8rc = ADDItoc8 @i, $x2
142+
; CHECK64-NOOPT: $x3 = COPY %[[SCRATCH]]
143+
115144
; TEST64: .addr
116145
; TEST64: la 3, i[TD](2)
117146

0 commit comments

Comments
 (0)