xref: /llvm-project/llvm/test/CodeGen/WebAssembly/legalize.ll (revision 73856247eef35f5336e485dc009842a5b991c421)
1; RUN: llc < %s -asm-verbose=false -mcpu=mvp -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s
2
3; Test various types and operators that need to be legalized.
4
5target triple = "wasm32-unknown-unknown"
6
7; CHECK-LABEL: shl_i3:
8; CHECK: i32.const   $push0=, 7{{$}}
9; CHECK: i32.and     $push1=, $1, $pop0{{$}}
10; CHECK: i32.shl     $push2=, $0, $pop1{{$}}
11define i3 @shl_i3(i3 %a, i3 %b, ptr %p) {
12  %t = shl i3 %a, %b
13  ret i3 %t
14}
15
16; CHECK-LABEL: shl_i53:
17; CHECK: i64.const   $push0=, 9007199254740991{{$}}
18; CHECK: i64.and     $push1=, $1, $pop0{{$}}
19; CHECK: i64.shl     $push2=, $0, $pop1{{$}}
20define i53 @shl_i53(i53 %a, i53 %b, ptr %p) {
21  %t = shl i53 %a, %b
22  ret i53 %t
23}
24
25; CHECK-LABEL: sext_in_reg_i32_i64:
26; CHECK: i64.shl
27; CHECK: i64.shr_s
28define i64 @sext_in_reg_i32_i64(i64 %a) {
29  %b = shl i64 %a, 32
30  %c = ashr i64 %b, 32
31  ret i64 %c
32}
33
34; CHECK-LABEL: fpext_f32_f64:
35; CHECK: f32.load $push0=, 0($0){{$}}
36; CHECK: f64.promote_f32 $push1=, $pop0{{$}}
37; CHECK: return $pop1{{$}}
38define double @fpext_f32_f64(ptr %p) {
39  %v = load float, ptr %p
40  %e = fpext float %v to double
41  ret double %e
42}
43
44; CHECK-LABEL: fpconv_f64_f32:
45; CHECK: f64.load $push0=, 0($0){{$}}
46; CHECK: f32.demote_f64 $push1=, $pop0{{$}}
47; CHECK: return $pop1{{$}}
48define float @fpconv_f64_f32(ptr %p) {
49  %v = load double, ptr %p
50  %e = fptrunc double %v to float
51  ret float %e
52}
53
54; Check that big shifts work. This generates a big pile of code from the
55; legalizer; the main thing here is that we don't abort.
56
57; CHECK-LABEL: bigshift:
58define i1024 @bigshift(i1024 %a, i1024 %b) {
59    %c = shl i1024 %a, %b
60    ret i1024 %c
61}
62