1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-linux-gnu -o - | FileCheck %s
4 ; This test checks that only a single jae gets generated in the final code
5 ; for lowering the CMOV pseudos that get created for this IR. The tricky part
6 ; of this test is that it tests the special PHI operand rewriting code in
7 ; X86TargetLowering::EmitLoweredSelect.
9 define double @foo1(float %p1, double %p2, double %p3) nounwind {
11 %c1 = fcmp oge float %p1, 0.000000e+00
12 %d0 = fadd double %p2, 1.25e0
13 %d1 = fadd double %p3, 1.25e0
14 %d2 = select i1 %c1, double %d0, double %d1
15 %d3 = select i1 %c1, double %d2, double %p2
16 %d4 = select i1 %c1, double %d3, double %p3
17 %d5 = fsub double %d2, %d3
18 %d6 = fadd double %d5, %d4
22 ; This test checks that only a single jae gets generated in the final code
23 ; for lowering the CMOV pseudos that get created for this IR. The tricky part
24 ; of this test is that it tests the special PHI operand rewriting code in
25 ; X86TargetLowering::EmitLoweredSelect.
27 define double @foo2(float %p1, double %p2, double %p3) nounwind {
29 ; CHECK: # %bb.0: # %entry
30 ; CHECK-NEXT: xorps %xmm3, %xmm3
31 ; CHECK-NEXT: ucomiss %xmm3, %xmm0
32 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = [1.25E+0,0.0E+0]
33 ; CHECK-NEXT: jae .LBB1_1
34 ; CHECK-NEXT: # %bb.2: # %entry
35 ; CHECK-NEXT: addsd %xmm0, %xmm2
36 ; CHECK-NEXT: movapd %xmm2, %xmm0
37 ; CHECK-NEXT: movapd %xmm2, %xmm1
38 ; CHECK-NEXT: jmp .LBB1_3
39 ; CHECK-NEXT: .LBB1_1:
40 ; CHECK-NEXT: addsd %xmm1, %xmm0
41 ; CHECK-NEXT: .LBB1_3: # %entry
42 ; CHECK-NEXT: subsd %xmm1, %xmm0
43 ; CHECK-NEXT: addsd %xmm2, %xmm0
46 %c1 = fcmp oge float %p1, 0.000000e+00
47 %d0 = fadd double %p2, 1.25e0
48 %d1 = fadd double %p3, 1.25e0
49 %d2 = select i1 %c1, double %d0, double %d1
50 %d3 = select i1 %c1, double %p2, double %d2
51 %d4 = select i1 %c1, double %p3, double %d3
52 %d5 = fsub double %d2, %d3
53 %d6 = fadd double %d5, %d4
57 ; This test checks that only a single js gets generated in the final code
58 ; for lowering the CMOV pseudos that get created for this IR. The tricky part
59 ; of this test is that it tests the special PHI operand rewriting code in
60 ; X86TargetLowering::EmitLoweredSelect. It also tests to make sure all
61 ; the operands of the resulting instructions are from the proper places.
63 define double @foo3(i32 %p1, double %p2, double %p3,
65 ; CHECK: # %bb.0: # %entry
66 ; CHECK-NEXT: testl %edi, %edi
67 ; CHECK-NEXT: js .LBB2_2
68 ; CHECK-NEXT: # %bb.1: # %entry
69 ; CHECK-NEXT: movapd %xmm2, %xmm1
70 ; CHECK-NEXT: movapd %xmm2, %xmm0
71 ; CHECK-NEXT: .LBB2_2: # %entry
72 ; CHECK-NEXT: divsd %xmm1, %xmm0
74 double %p4, double %p5) nounwind {
76 %c1 = icmp slt i32 %p1, 0
77 %d2 = select i1 %c1, double %p2, double %p3
78 %d3 = select i1 %c1, double %p3, double %p4
79 %d4 = select i1 %c1, double %d2, double %d3
80 %d5 = fdiv double %d4, %d3
84 ; This test checks that only a single js gets generated in the final code
85 ; for lowering the CMOV pseudos that get created for this IR. The tricky part
86 ; of this test is that it tests the special PHI operand rewriting code in
87 ; X86TargetLowering::EmitLoweredSelect. It also tests to make sure all
88 ; the operands of the resulting instructions are from the proper places
89 ; when the "opposite condition" handling code in the compiler is used.
90 ; This should be the same code as foo3 above, because we use the opposite
91 ; condition code in the second two selects, but we also swap the operands
92 ; of the selects to give the same actual computation.
94 define double @foo4(i32 %p1, double %p2, double %p3,
96 ; CHECK: # %bb.0: # %entry
97 ; CHECK-NEXT: testl %edi, %edi
98 ; CHECK-NEXT: js .LBB3_2
99 ; CHECK-NEXT: # %bb.1: # %entry
100 ; CHECK-NEXT: movapd %xmm2, %xmm1
101 ; CHECK-NEXT: movapd %xmm2, %xmm0
102 ; CHECK-NEXT: .LBB3_2: # %entry
103 ; CHECK-NEXT: divsd %xmm1, %xmm0
105 double %p4, double %p5) nounwind {
107 %c1 = icmp slt i32 %p1, 0
108 %d2 = select i1 %c1, double %p2, double %p3
109 %c2 = icmp sge i32 %p1, 0
110 %d3 = select i1 %c2, double %p4, double %p3
111 %d4 = select i1 %c2, double %d3, double %d2
112 %d5 = fdiv double %d4, %d3
116 ; This test checks that only a single jae gets generated in the final code
117 ; for lowering the CMOV pseudos that get created for this IR. The tricky part
118 ; of this test is that it tests the special code in CodeGenPrepare.
120 define double @foo5(float %p1, double %p2, double %p3) nounwind {
122 ; CHECK: # %bb.0: # %entry
123 ; CHECK-NEXT: xorps %xmm3, %xmm3
124 ; CHECK-NEXT: ucomiss %xmm3, %xmm0
125 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = [1.25E+0,0.0E+0]
126 ; CHECK-NEXT: jae .LBB4_1
127 ; CHECK-NEXT: # %bb.2: # %select.false
128 ; CHECK-NEXT: addsd %xmm2, %xmm0
129 ; CHECK-NEXT: .LBB4_3: # %select.end
130 ; CHECK-NEXT: subsd %xmm1, %xmm0
131 ; CHECK-NEXT: addsd %xmm2, %xmm0
133 ; CHECK-NEXT: .LBB4_1:
134 ; CHECK-NEXT: addsd %xmm0, %xmm1
135 ; CHECK-NEXT: movapd %xmm1, %xmm0
136 ; CHECK-NEXT: movapd %xmm1, %xmm2
137 ; CHECK-NEXT: jmp .LBB4_3
139 %c1 = fcmp oge float %p1, 0.000000e+00
140 %d0 = fadd double %p2, 1.25e0
141 %d1 = fadd double %p3, 1.25e0
142 %d2 = select i1 %c1, double %d0, double %d1, !prof !0
143 %d3 = select i1 %c1, double %d2, double %p2, !prof !0
144 %d4 = select i1 %c1, double %d3, double %p3, !prof !0
145 %d5 = fsub double %d2, %d3
146 %d6 = fadd double %d5, %d4
150 ; We should expand select instructions into 3 conditional branches as their
151 ; condtions are different.
153 define double @foo6(float %p1, double %p2, double %p3) nounwind {
155 ; CHECK: # %bb.0: # %entry
156 ; CHECK-NEXT: movaps %xmm0, %xmm3
157 ; CHECK-NEXT: xorps %xmm0, %xmm0
158 ; CHECK-NEXT: ucomiss %xmm0, %xmm3
159 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = [1.25E+0,0.0E+0]
160 ; CHECK-NEXT: jae .LBB5_1
161 ; CHECK-NEXT: # %bb.2: # %select.false
162 ; CHECK-NEXT: addsd %xmm2, %xmm0
163 ; CHECK-NEXT: .LBB5_3: # %select.end
164 ; CHECK-NEXT: ucomiss {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm3
165 ; CHECK-NEXT: movapd %xmm0, %xmm4
166 ; CHECK-NEXT: jae .LBB5_5
167 ; CHECK-NEXT: # %bb.4: # %select.false2
168 ; CHECK-NEXT: movapd %xmm1, %xmm4
169 ; CHECK-NEXT: .LBB5_5: # %select.end1
170 ; CHECK-NEXT: ucomiss {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm3
171 ; CHECK-NEXT: movapd %xmm4, %xmm1
172 ; CHECK-NEXT: jae .LBB5_7
173 ; CHECK-NEXT: # %bb.6: # %select.false4
174 ; CHECK-NEXT: movapd %xmm2, %xmm1
175 ; CHECK-NEXT: .LBB5_7: # %select.end3
176 ; CHECK-NEXT: subsd %xmm4, %xmm0
177 ; CHECK-NEXT: addsd %xmm1, %xmm0
179 ; CHECK-NEXT: .LBB5_1:
180 ; CHECK-NEXT: addsd %xmm1, %xmm0
181 ; CHECK-NEXT: jmp .LBB5_3
183 %c1 = fcmp oge float %p1, 0.000000e+00
184 %c2 = fcmp oge float %p1, 1.000000e+00
185 %c3 = fcmp oge float %p1, 2.000000e+00
186 %d0 = fadd double %p2, 1.25e0
187 %d1 = fadd double %p3, 1.25e0
188 %d2 = select i1 %c1, double %d0, double %d1, !prof !0
189 %d3 = select i1 %c2, double %d2, double %p2, !prof !0
190 %d4 = select i1 %c3, double %d3, double %p3, !prof !0
191 %d5 = fsub double %d2, %d3
192 %d6 = fadd double %d5, %d4
196 declare void @llvm.dbg.value(metadata, metadata, metadata)
198 ; Like the test for @foo1, but check that the inserted dbg.value does not
199 ; affect codegen. The CHECK items below should always be identical to @foo1,
200 ; minus the DEBUG_VALUE line and changes in labels..
201 define double @foo1_g(float %p1, double %p2, double %p3) nounwind !dbg !4 {
202 ; CHECK-LABEL: foo1_g:
203 ; CHECK: # %bb.0: # %entry
204 ; CHECK-NEXT: xorps %xmm3, %xmm3
205 ; CHECK-NEXT: ucomiss %xmm3, %xmm0
206 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = [1.25E+0,0.0E+0]
207 ; CHECK-NEXT: jae .LBB6_1
208 ; CHECK-NEXT: # %bb.2: # %entry
209 ; CHECK-NEXT: addsd %xmm2, %xmm0
210 ; CHECK-NEXT: jmp .LBB6_3
211 ; CHECK-NEXT: .LBB6_1:
212 ; CHECK-NEXT: addsd %xmm0, %xmm1
213 ; CHECK-NEXT: movapd %xmm1, %xmm0
214 ; CHECK-NEXT: movapd %xmm1, %xmm2
215 ; CHECK-NEXT: .LBB6_3: # %entry
216 ; CHECK-NEXT: #DEBUG_VALUE: foobar:xyzzy <- undef
217 ; CHECK-NEXT: subsd %xmm1, %xmm0
218 ; CHECK-NEXT: addsd %xmm2, %xmm0
221 %c1 = fcmp oge float %p1, 0.000000e+00
222 %d0 = fadd double %p2, 1.25e0
223 %d1 = fadd double %p3, 1.25e0
224 %d2 = select i1 %c1, double %d0, double %d1
225 call void @llvm.dbg.value(metadata float undef, metadata !5, metadata !DIExpression()), !dbg !6
226 %d3 = select i1 %c1, double %d2, double %p2
227 %d4 = select i1 %c1, double %d3, double %p3
228 %d5 = fsub double %d2, %d3
229 %d6 = fadd double %d5, %d4
233 !llvm.module.flags = !{!1}
236 !0 = !{!"branch_weights", i32 1, i32 2000}
237 !1 = !{i32 2, !"Debug Info Version", i32 3}
238 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, nameTableKind: None)
239 !3 = !DIFile(filename: "test.c", directory: ".")
240 !4 = distinct !DISubprogram(name: "foobar", scope: !2, file: !3, line: 1, type: !9, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !8)
241 !5 = !DILocalVariable(name: "xyzzy", scope: !4, file: !3, line: 2, type: !7)
242 !6 = !DILocation(line: 1, column: 1, scope: !4)
243 !7 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
245 !9 = !DISubroutineType(types: !10)