]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGen/PowerPC/remove-redundant-toc-saves.ll
Vendor import of llvm trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / test / CodeGen / PowerPC / remove-redundant-toc-saves.ll
1 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
2 define signext i32 @test1(i32 signext %i, i32 (i32)* nocapture %Func, i32 (i32)* nocapture %Func2) {
3 entry:
4 ; CHECK-LABEL: test1:
5 ; CHECK:    std 2, 24(1)
6 ; CHECK-NOT:    std 2, 24(1)
7   %call = tail call signext i32 %Func(i32 signext %i)
8   %call1 = tail call signext i32 %Func2(i32 signext %i)
9   %add2 = add nsw i32 %call1, %call
10   ret i32 %add2
11 }
12
13 define signext i32 @test2(i32 signext %i, i32 signext %j, i32 (i32)* nocapture %Func, i32 (i32)* nocapture %Func2) {
14 entry:
15 ; CHECK-LABEL: test2:
16 ; CHECK:    std 2, 24(1)
17 ; CHECK-NOT:    std 2, 24(1)
18   %call = tail call signext i32 %Func(i32 signext %i)
19   %tobool = icmp eq i32 %j, 0
20   br i1 %tobool, label %if.end, label %if.then
21
22 if.then:                                          ; preds = %entry
23   %call1 = tail call signext i32 %Func(i32 signext %i)
24   %add2 = add nsw i32 %call1, %call
25   %call3 = tail call signext i32 %Func2(i32 signext %i)
26   %add4 = add nsw i32 %add2, %call3
27   br label %if.end
28
29 if.end:                                           ; preds = %entry, %if.then
30   %Sum.0 = phi i32 [ %add4, %if.then ], [ %call, %entry ]
31   %call5 = tail call signext i32 %Func(i32 signext %i)
32   %add6 = add nsw i32 %call5, %Sum.0
33   ret i32 %add6
34 }
35
36 ; Check for multiple TOC saves with if then else where neither dominates the other.
37 define signext i32 @test3(i32 signext %i, i32 (i32)* nocapture %Func, i32 (i32)* nocapture %Func2) {
38 ; CHECK-LABEL: test3:
39 ; CHECK:    std 2, 24(1)
40 ; CHECK:    std 2, 24(1)
41 ; CHECK-NOT:    std 2, 24(1)
42 entry:
43   %tobool = icmp eq i32 %i, 0
44   br i1 %tobool, label %if.else, label %if.then
45
46 if.then:                                          ; preds = %entry
47   %call = tail call signext i32 %Func(i32 signext %i)
48   br label %if.end
49
50 if.else:                                          ; preds = %entry
51   %call1 = tail call signext i32 %Func2(i32 signext 0)
52   br label %if.end
53
54 if.end:                                           ; preds = %if.else, %if.then
55   %Sum.0 = phi i32 [ %call, %if.then ], [ %call1, %if.else ]
56   %call3 = tail call signext i32 %Func(i32 signext %i)
57   %add4 = add nsw i32 %call3, %Sum.0
58   ret i32 %add4
59 }
60
61 define signext i32 @test4(i32 signext %i, i32 (i32)* nocapture %Func, i32 (i32)* nocapture %Func2) {
62 ; CHECK-LABEL: test4:
63 ; CHECK:    std 2, 24(1)
64 ; CHECK-NOT:    std 2, 24(1)
65
66 entry:
67   %call = tail call signext i32 %Func(i32 signext %i)
68   %tobool = icmp eq i32 %i, 0
69   br i1 %tobool, label %if.else, label %if.then
70
71 if.then:                                          ; preds = %entry
72   %call1 = tail call signext i32 %Func(i32 signext %i)
73   br label %if.end
74
75 if.else:                                          ; preds = %entry
76   %call3 = tail call signext i32 %Func2(i32 signext 0)
77   br label %if.end
78
79 if.end:                                           ; preds = %if.else, %if.then
80   %call1.pn = phi i32 [ %call1, %if.then ], [ %call3, %if.else ]
81   %Sum.0 = add nsw i32 %call1.pn, %call
82   ret i32 %Sum.0
83 }
84
85 ; Check for multiple TOC saves with if then where neither is redundant.
86 define signext i32 @test5(i32 signext %i, i32 (i32)* nocapture %Func, i32 (i32)* nocapture readnone %Func2) {
87 entry:
88 ; CHECK-LABEL: test5:
89 ; CHECK:    std 2, 24(1)
90 ; CHECK:    std 2, 24(1)
91
92   %tobool = icmp eq i32 %i, 0
93   br i1 %tobool, label %if.end, label %if.then
94
95 if.then:                                          ; preds = %entry
96   %call = tail call signext i32 %Func(i32 signext %i)
97   br label %if.end
98
99 if.end:                                           ; preds = %entry, %if.then
100   %Sum.0 = phi i32 [ %call, %if.then ], [ 0, %entry ]
101   %call1 = tail call signext i32 %Func(i32 signext %i)
102   %add2 = add nsw i32 %call1, %Sum.0
103   ret i32 %add2
104 }
105
106 ; Check for multiple TOC saves if there are dynamic allocations on the stack.
107 define signext i32 @test6(i32 signext %i, i32 (i32)* nocapture %Func, i32 (i32)* nocapture %Func2) {
108 entry:
109 ; CHECK-LABEL: test6:
110 ; CHECK:    std 2, 24(1)
111 ; CHECK:    std 2, 24(1)
112
113   %conv = sext i32 %i to i64
114   %0 = alloca i8, i64 %conv, align 16
115   %1 = bitcast i8* %0 to i32*
116   %call = tail call signext i32 %Func(i32 signext %i)
117   call void @useAlloca(i32* nonnull %1, i32 signext %call)
118   %call1 = call signext i32 %Func2(i32 signext %i)
119   %add2 = add nsw i32 %call1, %call
120   ret i32 %add2
121 }
122
123 declare void @useAlloca(i32*, i32 signext)