Skip to content

Commit 58b3837

Browse files
committed
AMDGPU: Be explicit about whether the high-word in SI_PC_ADD_REL_OFFSET is 0
Summary: Instead of encoding a high-word of 0 using a fake TargetGlobalAddress, just use a literal target constant. This simplifies some subsequent changes. The generated assembly is now more explicit about the kind of relocation that is to be used. Change-Id: I066835202d23b5941fa7a358eb4b89e9b71ab6f8 Reviewers: arsenm, rampitec Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61491 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363516 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d116e84 commit 58b3837

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4644,11 +4644,18 @@ buildPCRelGlobalAddress(SelectionDAG &DAG, const GlobalValue *GV,
46444644
// of the s_add_u32 instruction, we end up with an offset that is 4 bytes too
46454645
// small. This requires us to add 4 to the global variable offset in order to
46464646
// compute the correct address.
4647-
SDValue PtrLo = DAG.getTargetGlobalAddress(GV, DL, MVT::i32, Offset + 4,
4648-
GAFlags);
4649-
SDValue PtrHi = DAG.getTargetGlobalAddress(GV, DL, MVT::i32, Offset + 4,
4650-
GAFlags == SIInstrInfo::MO_NONE ?
4651-
GAFlags : GAFlags + 1);
4647+
unsigned LoFlags = GAFlags;
4648+
if (LoFlags == SIInstrInfo::MO_NONE)
4649+
LoFlags = SIInstrInfo::MO_REL32;
4650+
SDValue PtrLo =
4651+
DAG.getTargetGlobalAddress(GV, DL, MVT::i32, Offset + 4, LoFlags);
4652+
SDValue PtrHi;
4653+
if (GAFlags == SIInstrInfo::MO_NONE) {
4654+
PtrHi = DAG.getTargetConstant(0, DL, MVT::i32);
4655+
} else {
4656+
PtrHi =
4657+
DAG.getTargetGlobalAddress(GV, DL, MVT::i32, Offset + 4, GAFlags + 1);
4658+
}
46524659
return DAG.getNode(AMDGPUISD::PC_ADD_REL_OFFSET, DL, PtrVT, PtrLo, PtrHi);
46534660
}
46544661

lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,10 +1369,7 @@ bool SIInstrInfo::expandPostRAPseudo(MachineInstr &MI) const {
13691369

13701370
MachineInstrBuilder MIB = BuildMI(MF, DL, get(AMDGPU::S_ADDC_U32), RegHi)
13711371
.addReg(RegHi);
1372-
if (MI.getOperand(2).getTargetFlags() == SIInstrInfo::MO_NONE)
1373-
MIB.addImm(0);
1374-
else
1375-
MIB.add(MI.getOperand(2));
1372+
MIB.add(MI.getOperand(2));
13761373

13771374
Bundler.append(MIB);
13781375
finalizeBundle(MBB, Bundler.begin());

lib/Target/AMDGPU/SIInstructions.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,15 @@ def SI_PC_ADD_REL_OFFSET : SPseudoInstSI <
551551
(outs SReg_64:$dst),
552552
(ins si_ga:$ptr_lo, si_ga:$ptr_hi),
553553
[(set SReg_64:$dst,
554-
(i64 (SIpc_add_rel_offset (tglobaladdr:$ptr_lo), (tglobaladdr:$ptr_hi))))]> {
554+
(i64 (SIpc_add_rel_offset tglobaladdr:$ptr_lo, tglobaladdr:$ptr_hi)))]> {
555555
let Defs = [SCC];
556556
}
557557

558+
def : GCNPat <
559+
(SIpc_add_rel_offset tglobaladdr:$ptr_lo, 0),
560+
(SI_PC_ADD_REL_OFFSET $ptr_lo, (i32 0))
561+
>;
562+
558563
def : GCNPat <
559564
(AMDGPUinit_exec i64:$src),
560565
(SI_INIT_EXEC (as_i64imm $src))

test/CodeGen/AMDGPU/llvm.memcpy.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ define amdgpu_kernel void @test_small_memcpy_i64_global_to_global_align16(i64 ad
333333

334334
; FUNC-LABEL: {{^}}test_memcpy_const_string_align4:
335335
; SI: s_getpc_b64
336-
; SI: s_add_u32 s{{[0-9]+}}, s{{[0-9]+}}, hello.align4+20
336+
; SI: s_add_u32 s{{[0-9]+}}, s{{[0-9]+}}, hello.align4@rel32@lo+20
337337
; SI: s_addc_u32
338338
; SI-DAG: s_load_dwordx4
339339
; SI-DAG: s_load_dwordx4

test/CodeGen/AMDGPU/no-initializer-constant-addrspace.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; RUN: llc -march=amdgcn -mcpu=tonga -filetype=obj < %s | llvm-readobj -r --symbols | FileCheck %s -check-prefix=GCN
33
; RUN: llc -march=r600 -mcpu=cypress -filetype=obj < %s | llvm-readobj -r --symbols | FileCheck %s -check-prefix=EG
44

5-
; GCN: R_AMDGPU_REL32 extern_const_addrspace
5+
; GCN: R_AMDGPU_REL32_LO extern_const_addrspace
66
; EG: R_AMDGPU_ABS32 extern_const_addrspace
77

88
; CHECK-DAG: Name: extern_const_addrspace

0 commit comments

Comments
 (0)