blob: 1cd6da8c770852c74969fce1e13655c7040cb9c3 [file] [log] [blame]
Ulrich Weigand9e3577f2013-05-06 16:17:29 +00001; Test 64-bit floating-point comparison.
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
4
Richard Sandiforded1fab62013-07-03 10:10:02 +00005declare double @foo()
6
Ulrich Weigand9e3577f2013-05-06 16:17:29 +00007; Check comparison with registers.
8define i64 @f1(i64 %a, i64 %b, double %f1, double %f2) {
Stephen Lind24ab202013-07-14 06:24:09 +00009; CHECK-LABEL: f1:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000010; CHECK: cdbr %f0, %f2
Richard Sandiford586f4172013-05-21 08:53:17 +000011; CHECK-NEXT: je
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000012; CHECK: lgr %r2, %r3
13; CHECK: br %r14
14 %cond = fcmp oeq double %f1, %f2
15 %res = select i1 %cond, i64 %a, i64 %b
16 ret i64 %res
17}
18
19; Check the low end of the CDB range.
20define i64 @f2(i64 %a, i64 %b, double %f1, double *%ptr) {
Stephen Lind24ab202013-07-14 06:24:09 +000021; CHECK-LABEL: f2:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000022; CHECK: cdb %f0, 0(%r4)
Richard Sandiford586f4172013-05-21 08:53:17 +000023; CHECK-NEXT: je
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000024; CHECK: lgr %r2, %r3
25; CHECK: br %r14
26 %f2 = load double *%ptr
27 %cond = fcmp oeq double %f1, %f2
28 %res = select i1 %cond, i64 %a, i64 %b
29 ret i64 %res
30}
31
32; Check the high end of the aligned CDB range.
33define i64 @f3(i64 %a, i64 %b, double %f1, double *%base) {
Stephen Lind24ab202013-07-14 06:24:09 +000034; CHECK-LABEL: f3:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000035; CHECK: cdb %f0, 4088(%r4)
Richard Sandiford586f4172013-05-21 08:53:17 +000036; CHECK-NEXT: je
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000037; CHECK: lgr %r2, %r3
38; CHECK: br %r14
39 %ptr = getelementptr double *%base, i64 511
40 %f2 = load double *%ptr
41 %cond = fcmp oeq double %f1, %f2
42 %res = select i1 %cond, i64 %a, i64 %b
43 ret i64 %res
44}
45
46; Check the next doubleword up, which needs separate address logic.
47; Other sequences besides this one would be OK.
48define i64 @f4(i64 %a, i64 %b, double %f1, double *%base) {
Stephen Lind24ab202013-07-14 06:24:09 +000049; CHECK-LABEL: f4:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000050; CHECK: aghi %r4, 4096
51; CHECK: cdb %f0, 0(%r4)
Richard Sandiford586f4172013-05-21 08:53:17 +000052; CHECK-NEXT: je
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000053; CHECK: lgr %r2, %r3
54; CHECK: br %r14
55 %ptr = getelementptr double *%base, i64 512
56 %f2 = load double *%ptr
57 %cond = fcmp oeq double %f1, %f2
58 %res = select i1 %cond, i64 %a, i64 %b
59 ret i64 %res
60}
61
62; Check negative displacements, which also need separate address logic.
63define i64 @f5(i64 %a, i64 %b, double %f1, double *%base) {
Stephen Lind24ab202013-07-14 06:24:09 +000064; CHECK-LABEL: f5:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000065; CHECK: aghi %r4, -8
66; CHECK: cdb %f0, 0(%r4)
Richard Sandiford586f4172013-05-21 08:53:17 +000067; CHECK-NEXT: je
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000068; CHECK: lgr %r2, %r3
69; CHECK: br %r14
70 %ptr = getelementptr double *%base, i64 -1
71 %f2 = load double *%ptr
72 %cond = fcmp oeq double %f1, %f2
73 %res = select i1 %cond, i64 %a, i64 %b
74 ret i64 %res
75}
76
77; Check that CDB allows indices.
78define i64 @f6(i64 %a, i64 %b, double %f1, double *%base, i64 %index) {
Stephen Lind24ab202013-07-14 06:24:09 +000079; CHECK-LABEL: f6:
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000080; CHECK: sllg %r1, %r5, 3
81; CHECK: cdb %f0, 800(%r1,%r4)
Richard Sandiford586f4172013-05-21 08:53:17 +000082; CHECK-NEXT: je
Ulrich Weigand9e3577f2013-05-06 16:17:29 +000083; CHECK: lgr %r2, %r3
84; CHECK: br %r14
85 %ptr1 = getelementptr double *%base, i64 %index
86 %ptr2 = getelementptr double *%ptr1, i64 100
87 %f2 = load double *%ptr2
88 %cond = fcmp oeq double %f1, %f2
89 %res = select i1 %cond, i64 %a, i64 %b
90 ret i64 %res
91}
Richard Sandiforded1fab62013-07-03 10:10:02 +000092
93; Check that comparisons of spilled values can use CDB rather than CDBR.
94define double @f7(double *%ptr0) {
Stephen Lind24ab202013-07-14 06:24:09 +000095; CHECK-LABEL: f7:
Richard Sandiforded1fab62013-07-03 10:10:02 +000096; CHECK: brasl %r14, foo@PLT
97; CHECK: cdb {{%f[0-9]+}}, 160(%r15)
98; CHECK: br %r14
99 %ptr1 = getelementptr double *%ptr0, i64 2
100 %ptr2 = getelementptr double *%ptr0, i64 4
101 %ptr3 = getelementptr double *%ptr0, i64 6
102 %ptr4 = getelementptr double *%ptr0, i64 8
103 %ptr5 = getelementptr double *%ptr0, i64 10
104 %ptr6 = getelementptr double *%ptr0, i64 12
105 %ptr7 = getelementptr double *%ptr0, i64 14
106 %ptr8 = getelementptr double *%ptr0, i64 16
107 %ptr9 = getelementptr double *%ptr0, i64 18
108 %ptr10 = getelementptr double *%ptr0, i64 20
109
110 %val0 = load double *%ptr0
111 %val1 = load double *%ptr1
112 %val2 = load double *%ptr2
113 %val3 = load double *%ptr3
114 %val4 = load double *%ptr4
115 %val5 = load double *%ptr5
116 %val6 = load double *%ptr6
117 %val7 = load double *%ptr7
118 %val8 = load double *%ptr8
119 %val9 = load double *%ptr9
120 %val10 = load double *%ptr10
121
122 %ret = call double @foo()
123
124 %cmp0 = fcmp olt double %ret, %val0
125 %cmp1 = fcmp olt double %ret, %val1
126 %cmp2 = fcmp olt double %ret, %val2
127 %cmp3 = fcmp olt double %ret, %val3
128 %cmp4 = fcmp olt double %ret, %val4
129 %cmp5 = fcmp olt double %ret, %val5
130 %cmp6 = fcmp olt double %ret, %val6
131 %cmp7 = fcmp olt double %ret, %val7
132 %cmp8 = fcmp olt double %ret, %val8
133 %cmp9 = fcmp olt double %ret, %val9
134 %cmp10 = fcmp olt double %ret, %val10
135
136 %sel0 = select i1 %cmp0, double %ret, double 0.0
137 %sel1 = select i1 %cmp1, double %sel0, double 1.0
138 %sel2 = select i1 %cmp2, double %sel1, double 2.0
139 %sel3 = select i1 %cmp3, double %sel2, double 3.0
140 %sel4 = select i1 %cmp4, double %sel3, double 4.0
141 %sel5 = select i1 %cmp5, double %sel4, double 5.0
142 %sel6 = select i1 %cmp6, double %sel5, double 6.0
143 %sel7 = select i1 %cmp7, double %sel6, double 7.0
144 %sel8 = select i1 %cmp8, double %sel7, double 8.0
145 %sel9 = select i1 %cmp9, double %sel8, double 9.0
146 %sel10 = select i1 %cmp10, double %sel9, double 10.0
147
148 ret double %sel10
149}
Richard Sandiford9f11bc12013-08-07 11:03:34 +0000150
151; Check comparison with zero.
152define i64 @f8(i64 %a, i64 %b, double %f) {
153; CHECK-LABEL: f8:
154; CHECK: ltdbr %f0, %f0
155; CHECK-NEXT: je
156; CHECK: lgr %r2, %r3
157; CHECK: br %r14
158 %cond = fcmp oeq double %f, 0.0
159 %res = select i1 %cond, i64 %a, i64 %b
160 ret i64 %res
161}
Richard Sandiford24e597b2013-08-23 11:27:19 +0000162
163; Check the comparison can be reversed if that allows CDB to be used,
164define i64 @f9(i64 %a, i64 %b, double %f2, double *%ptr) {
165; CHECK-LABEL: f9:
166; CHECK: cdb %f0, 0(%r4)
167; CHECK-NEXT: jl {{\.L.*}}
168; CHECK: lgr %r2, %r3
169; CHECK: br %r14
170 %f1 = load double *%ptr
171 %cond = fcmp ogt double %f1, %f2
172 %res = select i1 %cond, i64 %a, i64 %b
173 ret i64 %res
174}