diff --git a/lib/Target/PowerPC/PPCTLSDynamicCall.cpp b/lib/Target/PowerPC/PPCTLSDynamicCall.cpp index 2dc0d825c80..a9d2e888f4b 100644 --- a/lib/Target/PowerPC/PPCTLSDynamicCall.cpp +++ b/lib/Target/PowerPC/PPCTLSDynamicCall.cpp @@ -99,6 +99,11 @@ protected: break; } + // Don't really need to save data to the stack - the clobbered + // registers are already saved when the SDNode (e.g. PPCaddiTlsgdLAddr) + // gets translated to the pseudo instruction (e.g. ADDItlsgdLADDR). + BuildMI(MBB, I, DL, TII->get(PPC::ADJCALLSTACKDOWN)).addImm(0); + // Expand into two ops built prior to the existing instruction. MachineInstr *Addi = BuildMI(MBB, I, DL, TII->get(Opc1), GPR3) .addReg(InReg); @@ -113,6 +118,8 @@ protected: .addReg(GPR3)); Call->addOperand(MI->getOperand(3)); + BuildMI(MBB, I, DL, TII->get(PPC::ADJCALLSTACKUP)).addImm(0).addImm(0); + BuildMI(MBB, I, DL, TII->get(TargetOpcode::COPY), OutReg) .addReg(GPR3); diff --git a/test/CodeGen/PowerPC/tls_get_addr_clobbers.ll b/test/CodeGen/PowerPC/tls_get_addr_clobbers.ll new file mode 100644 index 00000000000..400a1f297f0 --- /dev/null +++ b/test/CodeGen/PowerPC/tls_get_addr_clobbers.ll @@ -0,0 +1,54 @@ +; RUN: llc -mtriple="powerpc64le-unknown-linux-gnu" -relocation-model=pic < %s | FileCheck %s + +@a = thread_local global i32* null, align 8 + +define void @test_foo(i32* nocapture %x01, i32* nocapture %x02, i32* nocapture %x03, i32* nocapture %x04, i32* nocapture %x05, i32* nocapture %x06, i32* nocapture %x07, i32* nocapture %x08) #0 { +entry: + +; CHECK-LABEL: test_foo: +; CHECK: stdu 1, {{-?[0-9]+}}(1) +; CHECK-DAG: mr [[BACKUP_3:[0-9]+]], 3 +; CHECK-DAG: mr [[BACKUP_4:[0-9]+]], 4 +; CHECK-DAG: mr [[BACKUP_5:[0-9]+]], 5 +; CHECK-DAG: mr [[BACKUP_6:[0-9]+]], 6 +; CHECK-DAG: mr [[BACKUP_7:[0-9]+]], 7 +; CHECK-DAG: mr [[BACKUP_8:[0-9]+]], 8 +; CHECK-DAG: mr [[BACKUP_9:[0-9]+]], 9 +; CHECK-DAG: mr [[BACKUP_10:[0-9]+]], 10 +; CHECK-DAG: std [[BACKUP_3]], {{[0-9]+}}(1) +; CHECK-DAG: std [[BACKUP_4]], {{[0-9]+}}(1) +; CHECK-DAG: std [[BACKUP_5]], {{[0-9]+}}(1) +; CHECK-DAG: std [[BACKUP_6]], {{[0-9]+}}(1) +; CHECK-DAG: std [[BACKUP_7]], {{[0-9]+}}(1) +; CHECK-DAG: std [[BACKUP_8]], {{[0-9]+}}(1) +; CHECK-DAG: std [[BACKUP_9]], {{[0-9]+}}(1) +; CHECK-DAG: std [[BACKUP_10]], {{[0-9]+}}(1) +; CHECK: bl __tls_get_addr +; CHECK-DAG: stw 3, 0([[BACKUP_3]]) +; CHECK-DAG: stw 3, 0([[BACKUP_4]]) +; CHECK-DAG: stw 3, 0([[BACKUP_5]]) +; CHECK-DAG: stw 3, 0([[BACKUP_6]]) +; CHECK-DAG: stw 3, 0([[BACKUP_7]]) +; CHECK-DAG: stw 3, 0([[BACKUP_8]]) +; CHECK-DAG: stw 3, 0([[BACKUP_9]]) +; CHECK-DAG: stw 3, 0([[BACKUP_10]]) +; CHECK: blr + + %0 = load i32*, i32** @a, align 8 + %cmp = icmp eq i32* %0, null + br i1 %cmp, label %return, label %if.end + +if.end: ; preds = %entry + store i32 0, i32* %x01, align 4 + store i32 0, i32* %x02, align 4 + store i32 0, i32* %x03, align 4 + store i32 0, i32* %x04, align 4 + store i32 0, i32* %x05, align 4 + store i32 0, i32* %x06, align 4 + store i32 0, i32* %x07, align 4 + store i32 0, i32* %x08, align 4 + br label %return + +return: ; preds = %entry, %if.end + ret void +} diff --git a/test/CodeGen/PowerPC/tls_get_addr_stackframe.ll b/test/CodeGen/PowerPC/tls_get_addr_stackframe.ll new file mode 100644 index 00000000000..4a235983e6f --- /dev/null +++ b/test/CodeGen/PowerPC/tls_get_addr_stackframe.ll @@ -0,0 +1,32 @@ +; RUN: llc -mtriple="powerpc64le-unknown-linux-gnu" -relocation-model=pic < %s | FileCheck %s +; CHECK-LABEL: foo_test: +; CHECK: mflr 0 +; CHECK: __tls_get_addr + +%struct1.2.41 = type { %struct2.0.39, %struct3.1.40, %struct1.2.41* } +%struct2.0.39 = type { i64, i32, i32, i32, i32 } +%struct3.1.40 = type { [160 x i8] } + +@tls_var = external thread_local global %struct1.2.41*, align 8 + +define void @foo_test() { + %1 = load %struct1.2.41*, %struct1.2.41** @tls_var, align 8 + br i1 undef, label %foo.exit, label %2 + +;