Skip to content

Commit cd9bab2

Browse files
author
Chen Zheng
authored
[PowerPC] handle toc-data in load selection of fast-isel (#91916)
Support the address selection for toc-data globals in fast isel. This benefits instruction selection for fast-isel for toc data symbol for example for load selection. This also aligns the code generation with/without -mtocdata.
1 parent f9e9e59 commit cd9bab2

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

llvm/lib/Target/PowerPC/PPCFastISel.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,16 +2074,15 @@ 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-
20832077
PPCFuncInfo->setUsesTOCBasePtr();
2078+
bool IsAIXTocData = TM.getTargetTriple().isOSAIX() &&
2079+
isa<GlobalVariable>(GV) &&
2080+
cast<GlobalVariable>(GV)->hasAttribute("toc-data");
2081+
20842082
// For small code model, generate a simple TOC load.
20852083
if (CModel == CodeModel::Small)
2086-
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(PPC::LDtoc),
2084+
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
2085+
IsAIXTocData ? TII.get(PPC::ADDItoc8) : TII.get(PPC::LDtoc),
20872086
DestReg)
20882087
.addGlobalAddress(GV)
20892088
.addReg(PPC::X2);
@@ -2101,6 +2100,7 @@ unsigned PPCFastISel::PPCMaterializeGV(const GlobalValue *GV, MVT VT) {
21012100
HighPartReg).addReg(PPC::X2).addGlobalAddress(GV);
21022101

21032102
if (Subtarget->isGVIndirectSymbol(GV)) {
2103+
assert(!IsAIXTocData && "TOC data should always be direct.");
21042104
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(PPC::LDtocL),
21052105
DestReg).addGlobalAddress(GV).addReg(HighPartReg);
21062106
} else {

llvm/test/CodeGen/PowerPC/aix-tocdata-fastisel.ll

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
22
; RUN: llc < %s -mtriple=powerpc64-ibm-aix-xcoff -fast-isel -verify-machineinstrs \
33
; RUN: -code-model=small | FileCheck %s --check-prefix=SMALL
4-
5-
;; FIXME: when toc data for 64 big large code model is supported,
6-
;; add a run line for large code model too.
4+
; RUN: llc < %s -mtriple=powerpc64-ibm-aix-xcoff -fast-isel -verify-machineinstrs \
5+
; RUN: -code-model=large | FileCheck %s --check-prefix=LARGE
76

87
@a = global i32 0, align 4 #0
98

109
define signext i32 @foo() #1 {
1110
; SMALL-LABEL: foo:
1211
; SMALL: # %bb.0: # %entry
1312
; SMALL-NEXT: la 3, a[TD](2)
14-
; SMALL-NEXT: lwz 3, 0(3)
15-
; SMALL-NEXT: extsw 3, 3
13+
; SMALL-NEXT: lwa 3, 0(3)
1614
; SMALL-NEXT: blr
15+
;
16+
; LARGE-LABEL: foo:
17+
; LARGE: # %bb.0: # %entry
18+
; LARGE-NEXT: addis 3, a[TD]@u(2)
19+
; LARGE-NEXT: la 3, a[TD]@l(3)
20+
; LARGE-NEXT: lwa 3, 0(3)
21+
; LARGE-NEXT: blr
1722
entry:
1823
%0 = load i32, ptr @a, align 4
1924
ret i32 %0

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ define dso_local void @write_int(i32 signext %in) {
4949

5050
; CHECK64-NOOPT: name: write_int
5151
; CHECK64-NOOPT: %[[SUBREG:[0-9]+]]:gprc = COPY %{{[0-9]}}.sub_32
52-
; CHECK64-NOOPT: %[[ADDR:[0-9]+]]:g8rc_and_g8rc_nox0 = ADDItoc8 @i, $x2 :: (load (s64) from got)
53-
; CHECK64-NOOPT: STW %[[SUBREG]], 0, killed %[[ADDR]] :: (store (s32) into @i)
52+
; CHECK64-NOOPT: %[[ADDR:[0-9]+]]:g8rc_and_g8rc_nox0 = ADDItoc8 @i, $x2
53+
; CHECK64-NOOPT: STW %[[SUBREG]], 0, %[[ADDR]]
5454

5555
; TEST64: .write_int:
5656
; TEST64: la 4, i[TD](2)
@@ -141,7 +141,7 @@ define dso_local float @read_float() {
141141

142142
; CHECK64-NOOPT: name: read_float
143143
; CHECK64-NOOPT: %[[SCRATCH:[0-9]+]]:g8rc_and_g8rc_nox0 = ADDItoc8 @f, $x2
144-
; CHECK64-NOOPT: %{{[0-9]+}}:f4rc = LFS 0, killed %[[SCRATCH]]
144+
; CHECK64-NOOPT: %{{[0-9]+}}:f4rc = LFS 0, %[[SCRATCH]]
145145

146146
; TEST64: .read_float:
147147
; TEST64: la 3, f[TD](2)
@@ -228,7 +228,7 @@ define dso_local nonnull ptr @addr() {
228228
; CHECK64-NEXT: $x3 = COPY %[[SCRATCH]]
229229

230230
; CHECK64-NOOPT: name: addr
231-
; CHECK64-NOOPT: %[[SCRATCH:[0-9]+]]:g8rc = ADDItoc8 @i, $x2
231+
; CHECK64-NOOPT: %[[SCRATCH:[0-9]+]]:g8rc_and_g8rc_nox0 = ADDItoc8 @i, $x2
232232
; CHECK64-NOOPT: $x3 = COPY %[[SCRATCH]]
233233

234234
; TEST64: .addr

0 commit comments

Comments
 (0)