1; RUN: opt -S -inline -inline-threshold=275 < %s | FileCheck %s
2; PR13095
3
4; The performance of the c-ray benchmark largely depends on the inlining of a
5; specific call to @ray_sphere. This test case is designed to verify that it's
6; inlined at -O3.
7
8target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
9target triple = "x86_64-apple-macosx10.8.0"
10
11%struct.sphere = type { %struct.vec3, double, %struct.material, %struct.sphere* }
12%struct.vec3 = type { double, double, double }
13%struct.material = type { %struct.vec3, double, double }
14%struct.ray = type { %struct.vec3, %struct.vec3 }
15%struct.spoint = type { %struct.vec3, %struct.vec3, %struct.vec3, double }
16
17define i32 @caller(%struct.sphere* %i) {
18  %shadow_ray = alloca %struct.ray, align 8
19  call void @fix(%struct.ray* %shadow_ray)
20
21  %call = call i32 @ray_sphere(%struct.sphere* %i, %struct.ray* byval align 8 %shadow_ray, %struct.spoint* null)
22  ret i32 %call
23
24; CHECK-LABEL: @caller(
25; CHECK-NOT: call i32 @ray_sphere
26; CHECK: ret i32
27}
28
29declare void @fix(%struct.ray*)
30
31define i32 @ray_sphere(%struct.sphere* nocapture %sph, %struct.ray* nocapture byval align 8 %ray, %struct.spoint* %sp) nounwind uwtable ssp {
32  %1 = getelementptr inbounds %struct.ray* %ray, i64 0, i32 1, i32 0
33  %2 = load double* %1, align 8
34  %3 = fmul double %2, %2
35  %4 = getelementptr inbounds %struct.ray* %ray, i64 0, i32 1, i32 1
36  %5 = load double* %4, align 8
37  %6 = fmul double %5, %5
38  %7 = fadd double %3, %6
39  %8 = getelementptr inbounds %struct.ray* %ray, i64 0, i32 1, i32 2
40  %9 = load double* %8, align 8
41  %10 = fmul double %9, %9
42  %11 = fadd double %7, %10
43  %12 = fmul double %2, 2.000000e+00
44  %13 = getelementptr inbounds %struct.ray* %ray, i64 0, i32 0, i32 0
45  %14 = load double* %13, align 8
46  %15 = getelementptr inbounds %struct.sphere* %sph, i64 0, i32 0, i32 0
47  %16 = load double* %15, align 8
48  %17 = fsub double %14, %16
49  %18 = fmul double %12, %17
50  %19 = fmul double %5, 2.000000e+00
51  %20 = getelementptr inbounds %struct.ray* %ray, i64 0, i32 0, i32 1
52  %21 = load double* %20, align 8
53  %22 = getelementptr inbounds %struct.sphere* %sph, i64 0, i32 0, i32 1
54  %23 = load double* %22, align 8
55  %24 = fsub double %21, %23
56  %25 = fmul double %19, %24
57  %26 = fadd double %18, %25
58  %27 = fmul double %9, 2.000000e+00
59  %28 = getelementptr inbounds %struct.ray* %ray, i64 0, i32 0, i32 2
60  %29 = load double* %28, align 8
61  %30 = getelementptr inbounds %struct.sphere* %sph, i64 0, i32 0, i32 2
62  %31 = load double* %30, align 8
63  %32 = fsub double %29, %31
64  %33 = fmul double %27, %32
65  %34 = fadd double %26, %33
66  %35 = fmul double %16, %16
67  %36 = fmul double %23, %23
68  %37 = fadd double %35, %36
69  %38 = fmul double %31, %31
70  %39 = fadd double %37, %38
71  %40 = fmul double %14, %14
72  %41 = fadd double %40, %39
73  %42 = fmul double %21, %21
74  %43 = fadd double %42, %41
75  %44 = fmul double %29, %29
76  %45 = fadd double %44, %43
77  %46 = fsub double -0.000000e+00, %16
78  %47 = fmul double %14, %46
79  %48 = fmul double %21, %23
80  %49 = fsub double %47, %48
81  %50 = fmul double %29, %31
82  %51 = fsub double %49, %50
83  %52 = fmul double %51, 2.000000e+00
84  %53 = fadd double %52, %45
85  %54 = getelementptr inbounds %struct.sphere* %sph, i64 0, i32 1
86  %55 = load double* %54, align 8
87  %56 = fmul double %55, %55
88  %57 = fsub double %53, %56
89  %58 = fmul double %34, %34
90  %59 = fmul double %11, 4.000000e+00
91  %60 = fmul double %59, %57
92  %61 = fsub double %58, %60
93  %62 = fcmp olt double %61, 0.000000e+00
94  br i1 %62, label %130, label %63
95
96; <label>:63                                      ; preds = %0
97  %64 = tail call double @sqrt(double %61) nounwind readnone
98  %65 = fsub double -0.000000e+00, %34
99  %66 = fsub double %64, %34
100  %67 = fmul double %11, 2.000000e+00
101  %68 = fdiv double %66, %67
102  %69 = fsub double %65, %64
103  %70 = fdiv double %69, %67
104  %71 = fcmp olt double %68, 1.000000e-06
105  %72 = fcmp olt double %70, 1.000000e-06
106  %or.cond = and i1 %71, %72
107  br i1 %or.cond, label %130, label %73
108
109; <label>:73                                      ; preds = %63
110  %74 = fcmp ogt double %68, 1.000000e+00
111  %75 = fcmp ogt double %70, 1.000000e+00
112  %or.cond1 = and i1 %74, %75
113  br i1 %or.cond1, label %130, label %76
114
115; <label>:76                                      ; preds = %73
116  %77 = icmp eq %struct.spoint* %sp, null
117  br i1 %77, label %130, label %78
118
119; <label>:78                                      ; preds = %76
120  %t1.0 = select i1 %71, double %70, double %68
121  %t2.0 = select i1 %72, double %t1.0, double %70
122  %79 = fcmp olt double %t1.0, %t2.0
123  %80 = select i1 %79, double %t1.0, double %t2.0
124  %81 = getelementptr inbounds %struct.spoint* %sp, i64 0, i32 3
125  store double %80, double* %81, align 8
126  %82 = fmul double %80, %2
127  %83 = fadd double %14, %82
128  %84 = getelementptr inbounds %struct.spoint* %sp, i64 0, i32 0, i32 0
129  store double %83, double* %84, align 8
130  %85 = fmul double %5, %80
131  %86 = fadd double %21, %85
132  %87 = getelementptr inbounds %struct.spoint* %sp, i64 0, i32 0, i32 1
133  store double %86, double* %87, align 8
134  %88 = fmul double %9, %80
135  %89 = fadd double %29, %88
136  %90 = getelementptr inbounds %struct.spoint* %sp, i64 0, i32 0, i32 2
137  store double %89, double* %90, align 8
138  %91 = load double* %15, align 8
139  %92 = fsub double %83, %91
140  %93 = load double* %54, align 8
141  %94 = fdiv double %92, %93
142  %95 = getelementptr inbounds %struct.spoint* %sp, i64 0, i32 1, i32 0
143  store double %94, double* %95, align 8
144  %96 = load double* %22, align 8
145  %97 = fsub double %86, %96
146  %98 = load double* %54, align 8
147  %99 = fdiv double %97, %98
148  %100 = getelementptr inbounds %struct.spoint* %sp, i64 0, i32 1, i32 1
149  store double %99, double* %100, align 8
150  %101 = load double* %30, align 8
151  %102 = fsub double %89, %101
152  %103 = load double* %54, align 8
153  %104 = fdiv double %102, %103
154  %105 = getelementptr inbounds %struct.spoint* %sp, i64 0, i32 1, i32 2
155  store double %104, double* %105, align 8
156  %106 = fmul double %2, %94
157  %107 = fmul double %5, %99
158  %108 = fadd double %106, %107
159  %109 = fmul double %9, %104
160  %110 = fadd double %108, %109
161  %111 = fmul double %110, 2.000000e+00
162  %112 = fmul double %94, %111
163  %113 = fsub double %112, %2
164  %114 = fsub double -0.000000e+00, %113
165  %115 = fmul double %99, %111
166  %116 = fsub double %115, %5
167  %117 = fsub double -0.000000e+00, %116
168  %118 = fmul double %104, %111
169  %119 = fsub double %118, %9
170  %120 = fsub double -0.000000e+00, %119
171  %.06 = getelementptr inbounds %struct.spoint* %sp, i64 0, i32 2, i32 0
172  %.18 = getelementptr inbounds %struct.spoint* %sp, i64 0, i32 2, i32 1
173  %.210 = getelementptr inbounds %struct.spoint* %sp, i64 0, i32 2, i32 2
174  %121 = fmul double %113, %113
175  %122 = fmul double %116, %116
176  %123 = fadd double %121, %122
177  %124 = fmul double %119, %119
178  %125 = fadd double %123, %124
179  %126 = tail call double @sqrt(double %125) nounwind readnone
180  %127 = fdiv double %114, %126
181  store double %127, double* %.06, align 8
182  %128 = fdiv double %117, %126
183  store double %128, double* %.18, align 8
184  %129 = fdiv double %120, %126
185  store double %129, double* %.210, align 8
186  br label %130
187
188; <label>:130                                     ; preds = %78, %76, %73, %63, %0
189  %.0 = phi i32 [ 0, %0 ], [ 0, %73 ], [ 0, %63 ], [ 1, %76 ], [ 1, %78 ]
190  ret i32 %.0
191}
192
193declare double @sqrt(double) nounwind readnone
194