llvm.org GIT mirror llvm / e51b530
Add call sequence start and end for __tls_get_addr This is a fix for bug http://llvm.org/bugs/show_bug.cgi?id=25839. For a PIC TLS variable access in a function, prologue (mflr followed by std and stdu) gets scheduled after a tls_get_addr call. tls_get_addr messed up LR but no one saves/restores it. Also added a test for save/restore clobbered registers during calling __tls_get_addr. Patch by Tim Shen git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257137 91177308-0d34-0410-b5e6-96231b3b80d8 Kyle Butt 4 years ago
3 changed file(s) with 93 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
9898 break;
9999 }
100100
101 // Don't really need to save data to the stack - the clobbered
102 // registers are already saved when the SDNode (e.g. PPCaddiTlsgdLAddr)
103 // gets translated to the pseudo instruction (e.g. ADDItlsgdLADDR).
104 BuildMI(MBB, I, DL, TII->get(PPC::ADJCALLSTACKDOWN)).addImm(0);
105
101106 // Expand into two ops built prior to the existing instruction.
102107 MachineInstr *Addi = BuildMI(MBB, I, DL, TII->get(Opc1), GPR3)
103108 .addReg(InReg);
111116 MachineInstr *Call = (BuildMI(MBB, I, DL, TII->get(Opc2), GPR3)
112117 .addReg(GPR3));
113118 Call->addOperand(MI->getOperand(3));
119
120 BuildMI(MBB, I, DL, TII->get(PPC::ADJCALLSTACKUP)).addImm(0).addImm(0);
114121
115122 BuildMI(MBB, I, DL, TII->get(TargetOpcode::COPY), OutReg)
116123 .addReg(GPR3);
0 ; RUN: llc -mtriple="powerpc64le-unknown-linux-gnu" -relocation-model=pic < %s | FileCheck %s
1
2 @a = thread_local global i32* null, align 8
3
4 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 {
5 entry:
6
7 ; CHECK-LABEL: test_foo:
8 ; CHECK: stdu 1, {{-?[0-9]+}}(1)
9 ; CHECK-DAG: mr [[BACKUP_3:[0-9]+]], 3
10 ; CHECK-DAG: mr [[BACKUP_4:[0-9]+]], 4
11 ; CHECK-DAG: mr [[BACKUP_5:[0-9]+]], 5
12 ; CHECK-DAG: mr [[BACKUP_6:[0-9]+]], 6
13 ; CHECK-DAG: mr [[BACKUP_7:[0-9]+]], 7
14 ; CHECK-DAG: mr [[BACKUP_8:[0-9]+]], 8
15 ; CHECK-DAG: mr [[BACKUP_9:[0-9]+]], 9
16 ; CHECK-DAG: mr [[BACKUP_10:[0-9]+]], 10
17 ; CHECK-DAG: std [[BACKUP_3]], {{[0-9]+}}(1)
18 ; CHECK-DAG: std [[BACKUP_4]], {{[0-9]+}}(1)
19 ; CHECK-DAG: std [[BACKUP_5]], {{[0-9]+}}(1)
20 ; CHECK-DAG: std [[BACKUP_6]], {{[0-9]+}}(1)
21 ; CHECK-DAG: std [[BACKUP_7]], {{[0-9]+}}(1)
22 ; CHECK-DAG: std [[BACKUP_8]], {{[0-9]+}}(1)
23 ; CHECK-DAG: std [[BACKUP_9]], {{[0-9]+}}(1)
24 ; CHECK-DAG: std [[BACKUP_10]], {{[0-9]+}}(1)
25 ; CHECK: bl __tls_get_addr
26 ; CHECK-DAG: stw 3, 0([[BACKUP_3]])
27 ; CHECK-DAG: stw 3, 0([[BACKUP_4]])
28 ; CHECK-DAG: stw 3, 0([[BACKUP_5]])
29 ; CHECK-DAG: stw 3, 0([[BACKUP_6]])
30 ; CHECK-DAG: stw 3, 0([[BACKUP_7]])
31 ; CHECK-DAG: stw 3, 0([[BACKUP_8]])
32 ; CHECK-DAG: stw 3, 0([[BACKUP_9]])
33 ; CHECK-DAG: stw 3, 0([[BACKUP_10]])
34 ; CHECK: blr
35
36 %0 = load i32*, i32** @a, align 8
37 %cmp = icmp eq i32* %0, null
38 br i1 %cmp, label %return, label %if.end
39
40 if.end: ; preds = %entry
41 store i32 0, i32* %x01, align 4
42 store i32 0, i32* %x02, align 4
43 store i32 0, i32* %x03, align 4
44 store i32 0, i32* %x04, align 4
45 store i32 0, i32* %x05, align 4
46 store i32 0, i32* %x06, align 4
47 store i32 0, i32* %x07, align 4
48 store i32 0, i32* %x08, align 4
49 br label %return
50
51 return: ; preds = %entry, %if.end
52 ret void
53 }
0 ; RUN: llc -mtriple="powerpc64le-unknown-linux-gnu" -relocation-model=pic < %s | FileCheck %s
1 ; CHECK-LABEL: foo_test:
2 ; CHECK: mflr 0
3 ; CHECK: __tls_get_addr
4
5 %struct1.2.41 = type { %struct2.0.39, %struct3.1.40, %struct1.2.41* }
6 %struct2.0.39 = type { i64, i32, i32, i32, i32 }
7 %struct3.1.40 = type { [160 x i8] }
8
9 @tls_var = external thread_local global %struct1.2.41*, align 8
10
11 define void @foo_test() {
12 %1 = load %struct1.2.41*, %struct1.2.41** @tls_var, align 8
13 br i1 undef, label %foo.exit, label %2
14
15 ;
16 br i1 undef, label %foo.exit, label %3
17
18 ;
19 %4 = getelementptr inbounds %struct1.2.41, %struct1.2.41* %1, i64 0, i32 0, i32 3
20 %5 = load i32, i32* %4, align 8
21 %6 = add nsw i32 %5, -1
22 %7 = icmp eq i32 %6, 0
23 br i1 %7, label %8, label %foo.exit
24
25 ;
26 tail call void undef(%struct1.2.41* undef, %struct1.2.41* nonnull undef)
27 br label %foo.exit
28
29 foo.exit: ; preds = %8, %3, %2, %0
30 ret void
31 }