1; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt | FileCheck %s
2
3; Test that basic 64-bit floating-point comparison operations assemble as
4; expected.
5
6target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
7target triple = "wasm32-unknown-unknown"
8
9; CHECK-LABEL: ord_f64:
10; CHECK-NEXT: .param f64, f64{{$}}
11; CHECK-NEXT: .result i32{{$}}
12; CHECK-NEXT: f64.eq $push[[NUM0:[0-9]+]]=, $0, $0{{$}}
13; CHECK-NEXT: f64.eq $push[[NUM1:[0-9]+]]=, $1, $1{{$}}
14; CHECK-NEXT: i32.and $push[[NUM2:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM1]]{{$}}
15; CHECK-NEXT: return $pop[[NUM2]]{{$}}
16define i32 @ord_f64(double %x, double %y) {
17  %a = fcmp ord double %x, %y
18  %b = zext i1 %a to i32
19  ret i32 %b
20}
21
22; CHECK-LABEL: uno_f64:
23; CHECK-NEXT: .param f64, f64{{$}}
24; CHECK-NEXT: .result i32{{$}}
25; CHECK-NEXT: f64.ne $push[[NUM0:[0-9]+]]=, $0, $0{{$}}
26; CHECK-NEXT: f64.ne $push[[NUM1:[0-9]+]]=, $1, $1{{$}}
27; CHECK-NEXT: i32.or $push[[NUM2:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM1]]{{$}}
28; CHECK-NEXT: return $pop[[NUM2]]{{$}}
29define i32 @uno_f64(double %x, double %y) {
30  %a = fcmp uno double %x, %y
31  %b = zext i1 %a to i32
32  ret i32 %b
33}
34
35; CHECK-LABEL: oeq_f64:
36; CHECK-NEXT: .param f64, f64{{$}}
37; CHECK-NEXT: .result i32{{$}}
38; CHECK-NEXT: f64.eq $push[[NUM:[0-9]+]]=, $0, $1{{$}}
39; CHECK-NEXT: return $pop[[NUM]]{{$}}
40define i32 @oeq_f64(double %x, double %y) {
41  %a = fcmp oeq double %x, %y
42  %b = zext i1 %a to i32
43  ret i32 %b
44}
45
46; CHECK-LABEL: une_f64:
47; CHECK: f64.ne $push[[NUM:[0-9]+]]=, $0, $1{{$}}
48; CHECK-NEXT: return $pop[[NUM]]{{$}}
49define i32 @une_f64(double %x, double %y) {
50  %a = fcmp une double %x, %y
51  %b = zext i1 %a to i32
52  ret i32 %b
53}
54
55; CHECK-LABEL: olt_f64:
56; CHECK: f64.lt $push[[NUM:[0-9]+]]=, $0, $1{{$}}
57; CHECK-NEXT: return $pop[[NUM]]{{$}}
58define i32 @olt_f64(double %x, double %y) {
59  %a = fcmp olt double %x, %y
60  %b = zext i1 %a to i32
61  ret i32 %b
62}
63
64; CHECK-LABEL: ole_f64:
65; CHECK: f64.le $push[[NUM:[0-9]+]]=, $0, $1{{$}}
66; CHECK-NEXT: return $pop[[NUM]]{{$}}
67define i32 @ole_f64(double %x, double %y) {
68  %a = fcmp ole double %x, %y
69  %b = zext i1 %a to i32
70  ret i32 %b
71}
72
73; CHECK-LABEL: ogt_f64:
74; CHECK: f64.gt $push[[NUM:[0-9]+]]=, $0, $1{{$}}
75; CHECK-NEXT: return $pop[[NUM]]{{$}}
76define i32 @ogt_f64(double %x, double %y) {
77  %a = fcmp ogt double %x, %y
78  %b = zext i1 %a to i32
79  ret i32 %b
80}
81
82; CHECK-LABEL: oge_f64:
83; CHECK: f64.ge $push[[NUM:[0-9]+]]=, $0, $1{{$}}
84; CHECK-NEXT: return $pop[[NUM]]{{$}}
85define i32 @oge_f64(double %x, double %y) {
86  %a = fcmp oge double %x, %y
87  %b = zext i1 %a to i32
88  ret i32 %b
89}
90
91; Expanded comparisons, which also check for NaN.
92
93; CHECK-LABEL: ueq_f64:
94; CHECK-NEXT: .param f64, f64{{$}}
95; CHECK-NEXT: .result i32{{$}}
96; CHECK-NEXT: f64.eq $push[[NUM0:[0-9]+]]=, $0, $1{{$}}
97; CHECK-NEXT: f64.ne $push[[NUM1:[0-9]+]]=, $0, $0{{$}}
98; CHECK-NEXT: f64.ne $push[[NUM2:[0-9]+]]=, $1, $1{{$}}
99; CHECK-NEXT: i32.or $push[[NUM3:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM2]]{{$}}
100; CHECK-NEXT: i32.or $push[[NUM4:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM3]]{{$}}
101; CHECK-NEXT: return $pop[[NUM4]]{{$}}
102define i32 @ueq_f64(double %x, double %y) {
103  %a = fcmp ueq double %x, %y
104  %b = zext i1 %a to i32
105  ret i32 %b
106}
107
108; CHECK-LABEL: one_f64:
109; CHECK-NEXT: .param f64, f64{{$}}
110; CHECK-NEXT: .result i32{{$}}
111; CHECK-NEXT: f64.ne $push[[NUM0:[0-9]+]]=, $0, $1{{$}}
112; CHECK-NEXT: f64.eq $push[[NUM1:[0-9]+]]=, $0, $0{{$}}
113; CHECK-NEXT: f64.eq $push[[NUM2:[0-9]+]]=, $1, $1{{$}}
114; CHECK-NEXT: i32.and $push[[NUM3:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM2]]{{$}}
115; CHECK-NEXT: i32.and $push[[NUM4:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM3]]{{$}}
116; CHECK-NEXT: return $pop[[NUM4]]
117define i32 @one_f64(double %x, double %y) {
118  %a = fcmp one double %x, %y
119  %b = zext i1 %a to i32
120  ret i32 %b
121}
122
123; CHECK-LABEL: ult_f64:
124; CHECK-NEXT: .param f64, f64{{$}}
125; CHECK-NEXT: .result i32{{$}}
126; CHECK-NEXT: f64.lt $push[[NUM0:[0-9]+]]=, $0, $1{{$}}
127; CHECK-NEXT: f64.ne $push[[NUM1:[0-9]+]]=, $0, $0{{$}}
128; CHECK-NEXT: f64.ne $push[[NUM2:[0-9]+]]=, $1, $1{{$}}
129; CHECK-NEXT: i32.or $push[[NUM3:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM2]]{{$}}
130; CHECK-NEXT: i32.or $push[[NUM4:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM3]]{{$}}
131; CHECK-NEXT: return $pop[[NUM4]]{{$}}
132define i32 @ult_f64(double %x, double %y) {
133  %a = fcmp ult double %x, %y
134  %b = zext i1 %a to i32
135  ret i32 %b
136}
137
138; CHECK-LABEL: ule_f64:
139; CHECK-NEXT: .param f64, f64{{$}}
140; CHECK-NEXT: .result i32{{$}}
141; CHECK-NEXT: f64.le $push[[NUM0:[0-9]+]]=, $0, $1{{$}}
142; CHECK-NEXT: f64.ne $push[[NUM1:[0-9]+]]=, $0, $0{{$}}
143; CHECK-NEXT: f64.ne $push[[NUM2:[0-9]+]]=, $1, $1{{$}}
144; CHECK-NEXT: i32.or $push[[NUM3:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM2]]{{$}}
145; CHECK-NEXT: i32.or $push[[NUM4:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM3]]{{$}}
146; CHECK-NEXT: return $pop[[NUM4]]{{$}}
147define i32 @ule_f64(double %x, double %y) {
148  %a = fcmp ule double %x, %y
149  %b = zext i1 %a to i32
150  ret i32 %b
151}
152
153; CHECK-LABEL: ugt_f64:
154; CHECK-NEXT: .param f64, f64{{$}}
155; CHECK-NEXT: .result i32{{$}}
156; CHECK-NEXT: f64.gt $push[[NUM0:[0-9]+]]=, $0, $1{{$}}
157; CHECK-NEXT: f64.ne $push[[NUM1:[0-9]+]]=, $0, $0{{$}}
158; CHECK-NEXT: f64.ne $push[[NUM2:[0-9]+]]=, $1, $1{{$}}
159; CHECK-NEXT: i32.or $push[[NUM3:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM2]]{{$}}
160; CHECK-NEXT: i32.or $push[[NUM4:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM3]]{{$}}
161; CHECK-NEXT: return $pop[[NUM4]]{{$}}
162define i32 @ugt_f64(double %x, double %y) {
163  %a = fcmp ugt double %x, %y
164  %b = zext i1 %a to i32
165  ret i32 %b
166}
167
168; CHECK-LABEL: uge_f64:
169; CHECK-NEXT: .param f64, f64{{$}}
170; CHECK-NEXT: .result i32{{$}}
171; CHECK-NEXT: f64.ge $push[[NUM0:[0-9]+]]=, $0, $1{{$}}
172; CHECK-NEXT: f64.ne $push[[NUM1:[0-9]+]]=, $0, $0{{$}}
173; CHECK-NEXT: f64.ne $push[[NUM2:[0-9]+]]=, $1, $1{{$}}
174; CHECK-NEXT: i32.or $push[[NUM3:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM2]]{{$}}
175; CHECK-NEXT: i32.or $push[[NUM4:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM3]]{{$}}
176; CHECK-NEXT: return $pop[[NUM4]]{{$}}
177define i32 @uge_f64(double %x, double %y) {
178  %a = fcmp uge double %x, %y
179  %b = zext i1 %a to i32
180  ret i32 %b
181}
182