blob: 913c4b0b19ea754ae027ea2b8d2bb030a988610e [file] [log] [blame]
Dan Gohman7d7409e2017-02-28 23:37:04 +00001; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -disable-wasm-explicit-locals | FileCheck %s
Dan Gohman311b4882015-09-15 00:55:19 +00002
3; Test that basic conversion operations assemble as expected.
4
Dan Gohman0c6f5ac2016-01-07 03:19:23 +00005target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
Dan Gohman7d7409e2017-02-28 23:37:04 +00006target triple = "wasm32-unknown-unknown-wasm"
Dan Gohman311b4882015-09-15 00:55:19 +00007
Dan Gohmane51c0582015-10-06 00:27:55 +00008; CHECK-LABEL: i32_wrap_i64:
9; CHECK-NEXT: .param i64{{$}}
10; CHECK-NEXT: .result i32{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +000011; CHECK-NEXT: i32.wrap/i64 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000012; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +000013define i32 @i32_wrap_i64(i64 %x) {
Dan Gohman311b4882015-09-15 00:55:19 +000014 %a = trunc i64 %x to i32
15 ret i32 %a
16}
Dan Gohmandc51b962015-10-03 02:10:28 +000017
Dan Gohmane51c0582015-10-06 00:27:55 +000018; CHECK-LABEL: i64_extend_s_i32:
Dan Gohman1270b0a2015-11-25 17:33:15 +000019; CHECK-NEXT: .param i32{{$}}
20; CHECK-NEXT: .result i64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +000021; CHECK-NEXT: i64.extend_s/i32 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000022; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +000023define i64 @i64_extend_s_i32(i32 %x) {
24 %a = sext i32 %x to i64
25 ret i64 %a
26}
27
Dan Gohmane51c0582015-10-06 00:27:55 +000028; CHECK-LABEL: i64_extend_u_i32:
Dan Gohman1270b0a2015-11-25 17:33:15 +000029; CHECK-NEXT: .param i32{{$}}
30; CHECK-NEXT: .result i64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +000031; CHECK-NEXT: i64.extend_u/i32 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000032; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +000033define i64 @i64_extend_u_i32(i32 %x) {
34 %a = zext i32 %x to i64
35 ret i64 %a
36}
37
Dan Gohmane51c0582015-10-06 00:27:55 +000038; CHECK-LABEL: i32_trunc_s_f32:
Dan Gohman1270b0a2015-11-25 17:33:15 +000039; CHECK-NEXT: .param f32{{$}}
40; CHECK-NEXT: .result i32{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +000041; CHECK-NEXT: i32.trunc_s/f32 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000042; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +000043define i32 @i32_trunc_s_f32(float %x) {
44 %a = fptosi float %x to i32
45 ret i32 %a
46}
47
Dan Gohmane51c0582015-10-06 00:27:55 +000048; CHECK-LABEL: i32_trunc_u_f32:
Dan Gohman1270b0a2015-11-25 17:33:15 +000049; CHECK-NEXT: .param f32{{$}}
50; CHECK-NEXT: .result i32{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +000051; CHECK-NEXT: i32.trunc_u/f32 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000052; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +000053define i32 @i32_trunc_u_f32(float %x) {
54 %a = fptoui float %x to i32
55 ret i32 %a
56}
57
Dan Gohmane51c0582015-10-06 00:27:55 +000058; CHECK-LABEL: i32_trunc_s_f64:
Dan Gohman1270b0a2015-11-25 17:33:15 +000059; CHECK-NEXT: .param f64{{$}}
60; CHECK-NEXT: .result i32{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +000061; CHECK-NEXT: i32.trunc_s/f64 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000062; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +000063define i32 @i32_trunc_s_f64(double %x) {
64 %a = fptosi double %x to i32
65 ret i32 %a
66}
67
Dan Gohmane51c0582015-10-06 00:27:55 +000068; CHECK-LABEL: i32_trunc_u_f64:
Dan Gohman1270b0a2015-11-25 17:33:15 +000069; CHECK-NEXT: .param f64{{$}}
70; CHECK-NEXT: .result i32{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +000071; CHECK-NEXT: i32.trunc_u/f64 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000072; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +000073define i32 @i32_trunc_u_f64(double %x) {
74 %a = fptoui double %x to i32
75 ret i32 %a
76}
77
Dan Gohmane51c0582015-10-06 00:27:55 +000078; CHECK-LABEL: i64_trunc_s_f32:
Dan Gohman1270b0a2015-11-25 17:33:15 +000079; CHECK-NEXT: .param f32{{$}}
80; CHECK-NEXT: .result i64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +000081; CHECK-NEXT: i64.trunc_s/f32 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000082; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +000083define i64 @i64_trunc_s_f32(float %x) {
84 %a = fptosi float %x to i64
85 ret i64 %a
86}
87
Dan Gohmane51c0582015-10-06 00:27:55 +000088; CHECK-LABEL: i64_trunc_u_f32:
Dan Gohman1270b0a2015-11-25 17:33:15 +000089; CHECK-NEXT: .param f32{{$}}
90; CHECK-NEXT: .result i64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +000091; CHECK-NEXT: i64.trunc_u/f32 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +000092; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +000093define i64 @i64_trunc_u_f32(float %x) {
94 %a = fptoui float %x to i64
95 ret i64 %a
96}
97
Dan Gohmane51c0582015-10-06 00:27:55 +000098; CHECK-LABEL: i64_trunc_s_f64:
Dan Gohman1270b0a2015-11-25 17:33:15 +000099; CHECK-NEXT: .param f64{{$}}
100; CHECK-NEXT: .result i64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +0000101; CHECK-NEXT: i64.trunc_s/f64 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000102; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +0000103define i64 @i64_trunc_s_f64(double %x) {
104 %a = fptosi double %x to i64
105 ret i64 %a
106}
107
Dan Gohmane51c0582015-10-06 00:27:55 +0000108; CHECK-LABEL: i64_trunc_u_f64:
Dan Gohman1270b0a2015-11-25 17:33:15 +0000109; CHECK-NEXT: .param f64{{$}}
110; CHECK-NEXT: .result i64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +0000111; CHECK-NEXT: i64.trunc_u/f64 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000112; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +0000113define i64 @i64_trunc_u_f64(double %x) {
114 %a = fptoui double %x to i64
115 ret i64 %a
116}
117
Dan Gohmane51c0582015-10-06 00:27:55 +0000118; CHECK-LABEL: f32_convert_s_i32:
Dan Gohman1270b0a2015-11-25 17:33:15 +0000119; CHECK-NEXT: .param i32{{$}}
120; CHECK-NEXT: .result f32{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +0000121; CHECK-NEXT: f32.convert_s/i32 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000122; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +0000123define float @f32_convert_s_i32(i32 %x) {
124 %a = sitofp i32 %x to float
125 ret float %a
126}
127
Dan Gohmane51c0582015-10-06 00:27:55 +0000128; CHECK-LABEL: f32_convert_u_i32:
Dan Gohman1270b0a2015-11-25 17:33:15 +0000129; CHECK-NEXT: .param i32{{$}}
130; CHECK-NEXT: .result f32{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +0000131; CHECK-NEXT: f32.convert_u/i32 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000132; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +0000133define float @f32_convert_u_i32(i32 %x) {
134 %a = uitofp i32 %x to float
135 ret float %a
136}
137
Dan Gohmane51c0582015-10-06 00:27:55 +0000138; CHECK-LABEL: f64_convert_s_i32:
Dan Gohman1270b0a2015-11-25 17:33:15 +0000139; CHECK-NEXT: .param i32{{$}}
140; CHECK-NEXT: .result f64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +0000141; CHECK-NEXT: f64.convert_s/i32 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000142; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +0000143define double @f64_convert_s_i32(i32 %x) {
144 %a = sitofp i32 %x to double
145 ret double %a
146}
147
Dan Gohmane51c0582015-10-06 00:27:55 +0000148; CHECK-LABEL: f64_convert_u_i32:
Dan Gohman1270b0a2015-11-25 17:33:15 +0000149; CHECK-NEXT: .param i32{{$}}
150; CHECK-NEXT: .result f64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +0000151; CHECK-NEXT: f64.convert_u/i32 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000152; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +0000153define double @f64_convert_u_i32(i32 %x) {
154 %a = uitofp i32 %x to double
155 ret double %a
156}
157
Dan Gohmane51c0582015-10-06 00:27:55 +0000158; CHECK-LABEL: f32_convert_s_i64:
Dan Gohman1270b0a2015-11-25 17:33:15 +0000159; CHECK-NEXT: .param i64{{$}}
160; CHECK-NEXT: .result f32{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +0000161; CHECK-NEXT: f32.convert_s/i64 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000162; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +0000163define float @f32_convert_s_i64(i64 %x) {
164 %a = sitofp i64 %x to float
165 ret float %a
166}
167
Dan Gohmane51c0582015-10-06 00:27:55 +0000168; CHECK-LABEL: f32_convert_u_i64:
Dan Gohman1270b0a2015-11-25 17:33:15 +0000169; CHECK-NEXT: .param i64{{$}}
170; CHECK-NEXT: .result f32{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +0000171; CHECK-NEXT: f32.convert_u/i64 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000172; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +0000173define float @f32_convert_u_i64(i64 %x) {
174 %a = uitofp i64 %x to float
175 ret float %a
176}
177
Dan Gohmane51c0582015-10-06 00:27:55 +0000178; CHECK-LABEL: f64_convert_s_i64:
Dan Gohman1270b0a2015-11-25 17:33:15 +0000179; CHECK-NEXT: .param i64{{$}}
180; CHECK-NEXT: .result f64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +0000181; CHECK-NEXT: f64.convert_s/i64 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000182; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +0000183define double @f64_convert_s_i64(i64 %x) {
184 %a = sitofp i64 %x to double
185 ret double %a
186}
187
Dan Gohmane51c0582015-10-06 00:27:55 +0000188; CHECK-LABEL: f64_convert_u_i64:
Dan Gohman1270b0a2015-11-25 17:33:15 +0000189; CHECK-NEXT: .param i64{{$}}
190; CHECK-NEXT: .result f64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +0000191; CHECK-NEXT: f64.convert_u/i64 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000192; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +0000193define double @f64_convert_u_i64(i64 %x) {
194 %a = uitofp i64 %x to double
195 ret double %a
196}
197
Dan Gohmane51c0582015-10-06 00:27:55 +0000198; CHECK-LABEL: f64_promote_f32:
Dan Gohman1270b0a2015-11-25 17:33:15 +0000199; CHECK-NEXT: .param f32{{$}}
200; CHECK-NEXT: .result f64{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +0000201; CHECK-NEXT: f64.promote/f32 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000202; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +0000203define double @f64_promote_f32(float %x) {
204 %a = fpext float %x to double
205 ret double %a
206}
207
Dan Gohmane51c0582015-10-06 00:27:55 +0000208; CHECK-LABEL: f32_demote_f64:
Dan Gohman1270b0a2015-11-25 17:33:15 +0000209; CHECK-NEXT: .param f64{{$}}
210; CHECK-NEXT: .result f32{{$}}
Dan Gohman700515f2015-11-23 21:55:57 +0000211; CHECK-NEXT: f32.demote/f64 $push[[NUM:[0-9]+]]=, $0{{$}}
Dan Gohman4ba48162015-11-18 16:12:01 +0000212; CHECK-NEXT: return $pop[[NUM]]{{$}}
Dan Gohmandc51b962015-10-03 02:10:28 +0000213define float @f32_demote_f64(double %x) {
214 %a = fptrunc double %x to float
215 ret float %a
216}
Dan Gohmandf00a9e2015-12-10 00:17:35 +0000217
218; If the high its are unused, LLVM will optimize sext/zext into anyext, which
219; we need to patterm-match back to a specific instruction.
220
221; CHECK-LABEL: anyext:
222; CHECK: i64.extend_u/i32 $push0=, $0{{$}}
223define i64 @anyext(i32 %x) {
224 %y = sext i32 %x to i64
225 %w = shl i64 %y, 32
226 ret i64 %w
227}
Dan Gohmandab313e2015-12-10 00:37:51 +0000228
229; CHECK-LABEL: bitcast_i32_to_float:
230; CHECK: f32.reinterpret/i32 $push0=, $0{{$}}
231define float @bitcast_i32_to_float(i32 %a) {
232 %t = bitcast i32 %a to float
233 ret float %t
234}
235
236; CHECK-LABEL: bitcast_float_to_i32:
237; CHECK: i32.reinterpret/f32 $push0=, $0{{$}}
238define i32 @bitcast_float_to_i32(float %a) {
239 %t = bitcast float %a to i32
240 ret i32 %t
241}
242
243; CHECK-LABEL: bitcast_i64_to_double:
244; CHECK: f64.reinterpret/i64 $push0=, $0{{$}}
245define double @bitcast_i64_to_double(i64 %a) {
246 %t = bitcast i64 %a to double
247 ret double %t
248}
249
250; CHECK-LABEL: bitcast_double_to_i64:
251; CHECK: i64.reinterpret/f64 $push0=, $0{{$}}
252define i64 @bitcast_double_to_i64(double %a) {
253 %t = bitcast double %a to i64
254 ret i64 %t
255}