llvm.org GIT mirror llvm / 0118969
WebAssembly: emit `(func (param t) (result t))` s-expressions Summary: Match spec format: https://github.com/WebAssembly/spec/blob/master/ml-proto/test/fac.wasm Reviewers: sunfish Subscribers: llvm-commits, jfb Differential Revision: http://reviews.llvm.org/D12307 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245986 91177308-0d34-0410-b5e6-96231b3b80d8 JF Bastien 5 years ago
18 changed file(s) with 329 addition(s) and 148 deletion(s). Raw diff Collapse all Expand all
2626 #include "llvm/IR/DataLayout.h"
2727 #include "llvm/IR/DebugInfo.h"
2828 #include "llvm/MC/MCStreamer.h"
29 #include "llvm/MC/MCSymbol.h"
2930 #include "llvm/Support/Debug.h"
3031 #include "llvm/Support/TargetRegistry.h"
3132 #include "llvm/Support/raw_ostream.h"
6465 //===------------------------------------------------------------------===//
6566 // AsmPrinter Implementation.
6667 //===------------------------------------------------------------------===//
68
69 void EmitFunctionEntryLabel() override;
70 void EmitFunctionBodyStart() override;
71 void EmitFunctionBodyEnd() override;
6772
6873 void EmitInstruction(const MachineInstr *MI) override;
6974 };
8489 }
8590
8691 static std::string toSymbol(StringRef S) { return ("$" + S).str(); }
92
93 static const char *toType(const Type *Ty) {
94 switch (Ty->getTypeID()) {
95 default: break;
96 case Type::FloatTyID: return "f32";
97 case Type::DoubleTyID: return "f64";
98 case Type::IntegerTyID:
99 switch (Ty->getIntegerBitWidth()) {
100 case 32: return "i32";
101 case 64: return "i64";
102 default: break;
103 }
104 }
105 DEBUG(dbgs() << "Invalid type "; Ty->print(dbgs()); dbgs() << '\n');
106 llvm_unreachable("invalid type");
107 return "";
108 }
109
110 void WebAssemblyAsmPrinter::EmitFunctionEntryLabel() {
111 SmallString<128> Str;
112 raw_svector_ostream OS(Str);
113
114 CurrentFnSym->redefineIfPossible();
115
116 // The function label could have already been emitted if two symbols end up
117 // conflicting due to asm renaming. Detect this and emit an error.
118 if (CurrentFnSym->isVariable())
119 report_fatal_error("'" + Twine(CurrentFnSym->getName()) +
120 "' is a protected alias");
121 if (CurrentFnSym->isDefined())
122 report_fatal_error("'" + Twine(CurrentFnSym->getName()) +
123 "' label emitted multiple times to assembly file");
124
125 OS << "(func " << toSymbol(CurrentFnSym->getName());
126 OutStreamer->EmitRawText(OS.str());
127 }
128
129 void WebAssemblyAsmPrinter::EmitFunctionBodyStart() {
130 SmallString<128> Str;
131 raw_svector_ostream OS(Str);
132 const Function *F = MF->getFunction();
133 for (const Argument &A : F->args())
134 OS << " (param " << toType(A.getType()) << ')';
135 const Type *Rt = F->getReturnType();
136 if (!Rt->isVoidTy())
137 OS << " (result " << toType(Rt) << ')';
138 OS << '\n';
139 OutStreamer->EmitRawText(OS.str());
140 }
141
142 void WebAssemblyAsmPrinter::EmitFunctionBodyEnd() {
143 SmallString<128> Str;
144 raw_svector_ostream OS(Str);
145 OS << ") ;; end func " << toSymbol(CurrentFnSym->getName()) << '\n';
146 OutStreamer->EmitRawText(OS.str());
147 }
87148
88149 void WebAssemblyAsmPrinter::EmitInstruction(const MachineInstr *MI) {
89150 DEBUG(dbgs() << "EmitInstruction: " << *MI << '\n');
1010 declare float @float_nullary()
1111 declare double @double_nullary()
1212
13 ; CHECK-LABEL: call_i32_nullary:
13 ; CHECK-LABEL: (func $call_i32_nullary
14 ; CHECK-NEXT: (result i32)
1415 ; CHECK-NEXT: (setlocal @0 (global $i32_nullary))
1516 ; CHECK-NEXT: (setlocal @1 (call @0))
1617 ; CHECK-NEXT: (return @1)
1920 ret i32 %r
2021 }
2122
22 ; CHECK-LABEL: call_i64_nullary:
23 ; CHECK-LABEL: (func $call_i64_nullary
24 ; CHECK-NEXT: (result i64)
2325 ; CHECK-NEXT: (setlocal @0 (global $i64_nullary))
2426 ; CHECK-NEXT: (setlocal @1 (call @0))
2527 ; CHECK-NEXT: (return @1)
2830 ret i64 %r
2931 }
3032
31 ; CHECK-LABEL: call_float_nullary:
33 ; CHECK-LABEL: (func $call_float_nullary
34 ; CHECK-NEXT: (result f32)
3235 ; CHECK-NEXT: (setlocal @0 (global $float_nullary))
3336 ; CHECK-NEXT: (setlocal @1 (call @0))
3437 ; CHECK-NEXT: (return @1)
3740 ret float %r
3841 }
3942
40 ; CHECK-LABEL: call_double_nullary:
43 ; CHECK-LABEL: (func $call_double_nullary
44 ; CHECK-NEXT: (result f64)
4145 ; CHECK-NEXT: (setlocal @0 (global $double_nullary))
4246 ; CHECK-NEXT: (setlocal @1 (call @0))
4347 ; CHECK-NEXT: (return @1)
4650 ret double %r
4751 }
4852
49 ; CHECK-LABEL: call_i32_unary:
53 ; CHECK-LABEL: (func $call_i32_unary
54 ; CHECK-NEXT: (param i32) (result i32)
5055 ; CHECK-NEXT: (setlocal @0 (argument 0))
5156 ; CHECK-NEXT: (setlocal @1 (global $i32_unary))
5257 ; CHECK-NEXT: (setlocal @2 (call @1 @0))
55 target datalayout = "e-p:32:32-i64:64-n32:64-S128"
66 target triple = "wasm32-unknown-unknown"
77
8 ; CHECK-LABEL: ord_f32:
8 ; CHECK-LABEL: (func $ord_f32
9 ; CHECK-NEXT: (param f32) (param f32) (result i32)
910 ; CHECK-NEXT: (setlocal @0 (argument 0))
1011 ; CHECK-NEXT: (setlocal @1 (argument 1))
1112 ; CHECK-NEXT: (setlocal @2 (eq @1 @1))
1819 ret i32 %b
1920 }
2021
21 ; CHECK-LABEL: uno_f32:
22 ; CHECK-LABEL: (func $uno_f32
23 ; CHECK-NEXT: (param f32) (param f32) (result i32)
2224 ; CHECK-NEXT: (setlocal @0 (argument 0))
2325 ; CHECK-NEXT: (setlocal @1 (argument 1))
2426 ; CHECK-NEXT: (setlocal @2 (ne @1 @1))
3133 ret i32 %b
3234 }
3335
34 ; CHECK-LABEL: oeq_f32:
36 ; CHECK-LABEL: (func $oeq_f32
37 ; CHECK-NEXT: (param f32) (param f32) (result i32)
3538 ; CHECK-NEXT: (setlocal @0 (argument 1))
3639 ; CHECK-NEXT: (setlocal @1 (argument 0))
3740 ; CHECK-NEXT: (setlocal @2 (eq @1 @0))
4245 ret i32 %b
4346 }
4447
45 ; CHECK-LABEL: une_f32:
48 ; CHECK-LABEL: (func $une_f32
4649 ; CHECK: (setlocal @2 (ne @1 @0))
4750 define i32 @une_f32(float %x, float %y) {
4851 %a = fcmp une float %x, %y
5053 ret i32 %b
5154 }
5255
53 ; CHECK-LABEL: olt_f32:
56 ; CHECK-LABEL: (func $olt_f32
5457 ; CHECK: (setlocal @2 (lt @1 @0))
5558 define i32 @olt_f32(float %x, float %y) {
5659 %a = fcmp olt float %x, %y
5861 ret i32 %b
5962 }
6063
61 ; CHECK-LABEL: ole_f32:
64 ; CHECK-LABEL: (func $ole_f32
6265 ; CHECK: (setlocal @2 (le @1 @0))
6366 define i32 @ole_f32(float %x, float %y) {
6467 %a = fcmp ole float %x, %y
6669 ret i32 %b
6770 }
6871
69 ; CHECK-LABEL: ogt_f32:
72 ; CHECK-LABEL: (func $ogt_f32
7073 ; CHECK: (setlocal @2 (gt @1 @0))
7174 define i32 @ogt_f32(float %x, float %y) {
7275 %a = fcmp ogt float %x, %y
7477 ret i32 %b
7578 }
7679
77 ; CHECK-LABEL: oge_f32:
80 ; CHECK-LABEL: (func $oge_f32
7881 ; CHECK: (setlocal @2 (ge @1 @0))
7982 define i32 @oge_f32(float %x, float %y) {
8083 %a = fcmp oge float %x, %y
8487
8588 ; Expanded comparisons, which also check for NaN.
8689
87 ; CHECK-LABEL: ueq_f32:
90 ; CHECK-LABEL: (func $ueq_f32
91 ; CHECK-NEXT: (param f32) (param f32) (result i32)
8892 ; CHECK-NEXT: (setlocal @0 (argument 1))
8993 ; CHECK-NEXT: (setlocal @1 (argument 0))
9094 ; CHECK-NEXT: (setlocal @2 (eq @1 @0))
99103 ret i32 %b
100104 }
101105
102 ; CHECK-LABEL: one_f32:
106 ; CHECK-LABEL: (func $one_f32
103107 ; CHECK: (setlocal @2 (ne @1 @0))
104108 define i32 @one_f32(float %x, float %y) {
105109 %a = fcmp one float %x, %y
107111 ret i32 %b
108112 }
109113
110 ; CHECK-LABEL: ult_f32:
114 ; CHECK-LABEL: (func $ult_f32
111115 ; CHECK: (setlocal @2 (lt @1 @0))
112116 define i32 @ult_f32(float %x, float %y) {
113117 %a = fcmp ult float %x, %y
115119 ret i32 %b
116120 }
117121
118 ; CHECK-LABEL: ule_f32:
122 ; CHECK-LABEL: (func $ule_f32
119123 ; CHECK: (setlocal @2 (le @1 @0))
120124 define i32 @ule_f32(float %x, float %y) {
121125 %a = fcmp ule float %x, %y
123127 ret i32 %b
124128 }
125129
126 ; CHECK-LABEL: ugt_f32:
130 ; CHECK-LABEL: (func $ugt_f32
127131 ; CHECK: (setlocal @2 (gt @1 @0))
128132 define i32 @ugt_f32(float %x, float %y) {
129133 %a = fcmp ugt float %x, %y
131135 ret i32 %b
132136 }
133137
134 ; CHECK-LABEL: uge_f32:
138 ; CHECK-LABEL: (func $uge_f32
135139 ; CHECK: (setlocal @2 (ge @1 @0))
136140 define i32 @uge_f32(float %x, float %y) {
137141 %a = fcmp uge float %x, %y
55 target datalayout = "e-p:32:32-i64:64-n32:64-S128"
66 target triple = "wasm32-unknown-unknown"
77
8 ; CHECK-LABEL: ord_f64:
8 ; CHECK-LABEL: (func $ord_f64
9 ; CHECK-NEXT: (param f64) (param f64) (result i32)
910 ; CHECK-NEXT: (setlocal @0 (argument 0))
1011 ; CHECK-NEXT: (setlocal @1 (argument 1))
1112 ; CHECK-NEXT: (setlocal @2 (eq @1 @1))
1819 ret i32 %b
1920 }
2021
21 ; CHECK-LABEL: uno_f64:
22 ; CHECK-LABEL: (func $uno_f64
23 ; CHECK-NEXT: (param f64) (param f64) (result i32)
2224 ; CHECK-NEXT: (setlocal @0 (argument 0))
2325 ; CHECK-NEXT: (setlocal @1 (argument 1))
2426 ; CHECK-NEXT: (setlocal @2 (ne @1 @1))
3133 ret i32 %b
3234 }
3335
34 ; CHECK-LABEL: oeq_f64:
36 ; CHECK-LABEL: (func $oeq_f64
37 ; CHECK-NEXT: (param f64) (param f64) (result i32)
3538 ; CHECK-NEXT: (setlocal @0 (argument 1))
3639 ; CHECK-NEXT: (setlocal @1 (argument 0))
3740 ; CHECK-NEXT: (setlocal @2 (eq @1 @0))
4245 ret i32 %b
4346 }
4447
45 ; CHECK-LABEL: une_f64:
48 ; CHECK-LABEL: (func $une_f64
4649 ; CHECK: (setlocal @2 (ne @1 @0))
4750 define i32 @une_f64(double %x, double %y) {
4851 %a = fcmp une double %x, %y
5053 ret i32 %b
5154 }
5255
53 ; CHECK-LABEL: olt_f64:
56 ; CHECK-LABEL: (func $olt_f64
5457 ; CHECK: (setlocal @2 (lt @1 @0))
5558 define i32 @olt_f64(double %x, double %y) {
5659 %a = fcmp olt double %x, %y
5861 ret i32 %b
5962 }
6063
61 ; CHECK-LABEL: ole_f64:
64 ; CHECK-LABEL: (func $ole_f64
6265 ; CHECK: (setlocal @2 (le @1 @0))
6366 define i32 @ole_f64(double %x, double %y) {
6467 %a = fcmp ole double %x, %y
6669 ret i32 %b
6770 }
6871
69 ; CHECK-LABEL: ogt_f64:
72 ; CHECK-LABEL: (func $ogt_f64
7073 ; CHECK: (setlocal @2 (gt @1 @0))
7174 define i32 @ogt_f64(double %x, double %y) {
7275 %a = fcmp ogt double %x, %y
7477 ret i32 %b
7578 }
7679
77 ; CHECK-LABEL: oge_f64:
80 ; CHECK-LABEL: (func $oge_f64
7881 ; CHECK: (setlocal @2 (ge @1 @0))
7982 define i32 @oge_f64(double %x, double %y) {
8083 %a = fcmp oge double %x, %y
8487
8588 ; Expanded comparisons, which also check for NaN.
8689
87 ; CHECK-LABEL: ueq_f64:
90 ; CHECK-LABEL: (func $ueq_f64
91 ; CHECK-NEXT: (param f64) (param f64) (result i32)
8892 ; CHECK-NEXT: (setlocal @0 (argument 1))
8993 ; CHECK-NEXT: (setlocal @1 (argument 0))
9094 ; CHECK-NEXT: (setlocal @2 (eq @1 @0))
99103 ret i32 %b
100104 }
101105
102 ; CHECK-LABEL: one_f64:
106 ; CHECK-LABEL: (func $one_f64
103107 ; CHECK: (setlocal @2 (ne @1 @0))
104108 define i32 @one_f64(double %x, double %y) {
105109 %a = fcmp one double %x, %y
107111 ret i32 %b
108112 }
109113
110 ; CHECK-LABEL: ult_f64:
114 ; CHECK-LABEL: (func $ult_f64
111115 ; CHECK: (setlocal @2 (lt @1 @0))
112116 define i32 @ult_f64(double %x, double %y) {
113117 %a = fcmp ult double %x, %y
115119 ret i32 %b
116120 }
117121
118 ; CHECK-LABEL: ule_f64:
122 ; CHECK-LABEL: (func $ule_f64
119123 ; CHECK: (setlocal @2 (le @1 @0))
120124 define i32 @ule_f64(double %x, double %y) {
121125 %a = fcmp ule double %x, %y
123127 ret i32 %b
124128 }
125129
126 ; CHECK-LABEL: ugt_f64:
130 ; CHECK-LABEL: (func $ugt_f64
127131 ; CHECK: (setlocal @2 (gt @1 @0))
128132 define i32 @ugt_f64(double %x, double %y) {
129133 %a = fcmp ugt double %x, %y
131135 ret i32 %b
132136 }
133137
134 ; CHECK-LABEL: uge_f64:
138 ; CHECK-LABEL: (func $uge_f64
135139 ; CHECK: (setlocal @2 (ge @1 @0))
136140 define i32 @uge_f64(double %x, double %y) {
137141 %a = fcmp uge double %x, %y
44 target datalayout = "e-p:32:32-i64:64-n32:64-S128"
55 target triple = "wasm32-unknown-unknown"
66
7 ; CHECK-LABEL: eq_i32:
7 ; CHECK-LABEL: (func $eq_i32
8 ; CHECK-NEXT: (param i32) (param i32) (result i32)
89 ; CHECK-NEXT: (setlocal @0 (argument 1))
910 ; CHECK-NEXT: (setlocal @1 (argument 0))
1011 ; CHECK-NEXT: (setlocal @2 (eq @1 @0))
1516 ret i32 %b
1617 }
1718
18 ; CHECK-LABEL: ne_i32:
19 ; CHECK-LABEL: (func $ne_i32
1920 ; CHECK: (setlocal @2 (ne @1 @0))
2021 define i32 @ne_i32(i32 %x, i32 %y) {
2122 %a = icmp ne i32 %x, %y
2324 ret i32 %b
2425 }
2526
26 ; CHECK-LABEL: slt_i32:
27 ; CHECK-LABEL: (func $slt_i32
2728 ; CHECK: (setlocal @2 (slt @1 @0))
2829 define i32 @slt_i32(i32 %x, i32 %y) {
2930 %a = icmp slt i32 %x, %y
3132 ret i32 %b
3233 }
3334
34 ; CHECK-LABEL: sle_i32:
35 ; CHECK-LABEL: (func $sle_i32
3536 ; CHECK: (setlocal @2 (sle @1 @0))
3637 define i32 @sle_i32(i32 %x, i32 %y) {
3738 %a = icmp sle i32 %x, %y
3940 ret i32 %b
4041 }
4142
42 ; CHECK-LABEL: ult_i32:
43 ; CHECK-LABEL: (func $ult_i32
4344 ; CHECK: (setlocal @2 (ult @1 @0))
4445 define i32 @ult_i32(i32 %x, i32 %y) {
4546 %a = icmp ult i32 %x, %y
4748 ret i32 %b
4849 }
4950
50 ; CHECK-LABEL: ule_i32:
51 ; CHECK-LABEL: (func $ule_i32
5152 ; CHECK: (setlocal @2 (ule @1 @0))
5253 define i32 @ule_i32(i32 %x, i32 %y) {
5354 %a = icmp ule i32 %x, %y
5556 ret i32 %b
5657 }
5758
58 ; CHECK-LABEL: sgt_i32:
59 ; CHECK-LABEL: (func $sgt_i32
5960 ; CHECK: (setlocal @2 (sgt @1 @0))
6061 define i32 @sgt_i32(i32 %x, i32 %y) {
6162 %a = icmp sgt i32 %x, %y
6364 ret i32 %b
6465 }
6566
66 ; CHECK-LABEL: sge_i32:
67 ; CHECK-LABEL: (func $sge_i32
6768 ; CHECK: (setlocal @2 (sge @1 @0))
6869 define i32 @sge_i32(i32 %x, i32 %y) {
6970 %a = icmp sge i32 %x, %y
7172 ret i32 %b
7273 }
7374
74 ; CHECK-LABEL: ugt_i32:
75 ; CHECK-LABEL: (func $ugt_i32
7576 ; CHECK: (setlocal @2 (ugt @1 @0))
7677 define i32 @ugt_i32(i32 %x, i32 %y) {
7778 %a = icmp ugt i32 %x, %y
7980 ret i32 %b
8081 }
8182
82 ; CHECK-LABEL: uge_i32:
83 ; CHECK-LABEL: (func $uge_i32
8384 ; CHECK: (setlocal @2 (uge @1 @0))
8485 define i32 @uge_i32(i32 %x, i32 %y) {
8586 %a = icmp uge i32 %x, %y
44 target datalayout = "e-p:32:32-i64:64-n32:64-S128"
55 target triple = "wasm32-unknown-unknown"
66
7 ; CHECK-LABEL: eq_i64:
7 ; CHECK-LABEL: (func $eq_i64
8 ; CHECK-NEXT: (param i64) (param i64) (result i32)
89 ; CHECK-NEXT: (setlocal @0 (argument 1))
910 ; CHECK-NEXT: (setlocal @1 (argument 0))
1011 ; CHECK-NEXT: (setlocal @2 (eq @1 @0))
1516 ret i32 %b
1617 }
1718
18 ; CHECK-LABEL: ne_i64:
19 ; CHECK-LABEL: (func $ne_i64
1920 ; CHECK: (setlocal @2 (ne @1 @0))
2021 define i32 @ne_i64(i64 %x, i64 %y) {
2122 %a = icmp ne i64 %x, %y
2324 ret i32 %b
2425 }
2526
26 ; CHECK-LABEL: slt_i64:
27 ; CHECK-LABEL: (func $slt_i64
2728 ; CHECK: (setlocal @2 (slt @1 @0))
2829 define i32 @slt_i64(i64 %x, i64 %y) {
2930 %a = icmp slt i64 %x, %y
3132 ret i32 %b
3233 }
3334
34 ; CHECK-LABEL: sle_i64:
35 ; CHECK-LABEL: (func $sle_i64
3536 ; CHECK: (setlocal @2 (sle @1 @0))
3637 define i32 @sle_i64(i64 %x, i64 %y) {
3738 %a = icmp sle i64 %x, %y
3940 ret i32 %b
4041 }
4142
42 ; CHECK-LABEL: ult_i64:
43 ; CHECK-LABEL: (func $ult_i64
4344 ; CHECK: (setlocal @2 (ult @1 @0))
4445 define i32 @ult_i64(i64 %x, i64 %y) {
4546 %a = icmp ult i64 %x, %y
4748 ret i32 %b
4849 }
4950
50 ; CHECK-LABEL: ule_i64:
51 ; CHECK-LABEL: (func $ule_i64
5152 ; CHECK: (setlocal @2 (ule @1 @0))
5253 define i32 @ule_i64(i64 %x, i64 %y) {
5354 %a = icmp ule i64 %x, %y
5556 ret i32 %b
5657 }
5758
58 ; CHECK-LABEL: sgt_i64:
59 ; CHECK-LABEL: (func $sgt_i64
5960 ; CHECK: (setlocal @2 (sgt @1 @0))
6061 define i32 @sgt_i64(i64 %x, i64 %y) {
6162 %a = icmp sgt i64 %x, %y
6364 ret i32 %b
6465 }
6566
66 ; CHECK-LABEL: sge_i64:
67 ; CHECK-LABEL: (func $sge_i64
6768 ; CHECK: (setlocal @2 (sge @1 @0))
6869 define i32 @sge_i64(i64 %x, i64 %y) {
6970 %a = icmp sge i64 %x, %y
7172 ret i32 %b
7273 }
7374
74 ; CHECK-LABEL: ugt_i64:
75 ; CHECK-LABEL: (func $ugt_i64
7576 ; CHECK: (setlocal @2 (ugt @1 @0))
7677 define i32 @ugt_i64(i64 %x, i64 %y) {
7778 %a = icmp ugt i64 %x, %y
7980 ret i32 %b
8081 }
8182
82 ; CHECK-LABEL: uge_i64:
83 ; CHECK-LABEL: (func $uge_i64
8384 ; CHECK: (setlocal @2 (uge @1 @0))
8485 define i32 @uge_i64(i64 %x, i64 %y) {
8586 %a = icmp uge i64 %x, %y
66
77 ; This tests very minimal fast-isel functionality.
88
9 ; CHECK-LABEL: immediate_f32
9 ; CHECK-LABEL: (func $immediate_f32
1010 ; CHECK: (immediate 0x1.4p1)
1111 define float @immediate_f32() {
1212 ret float 2.5
1313 }
1414
15 ; CHECK-LABEL: immediate_f64
15 ; CHECK-LABEL: (func $immediate_f64
1616 ; CHECK: (immediate 0x1.4p1)
1717 define double @immediate_f64() {
1818 ret double 2.5
1313 declare float @llvm.nearbyint.f32(float)
1414 declare float @llvm.rint.f32(float)
1515
16 ; CHECK-LABEL: fadd32:
16 ; CHECK-LABEL: (func $fadd32
17 ; CHECK-NEXT: (param f32) (param f32) (result f32)
1718 ; CHECK-NEXT: (setlocal @0 (argument 1))
1819 ; CHECK-NEXT: (setlocal @1 (argument 0))
1920 ; CHECK-NEXT: (setlocal @2 (fadd @1 @0))
2324 ret float %a
2425 }
2526
26 ; CHECK-LABEL: fsub32:
27 ; CHECK-LABEL: (func $fsub32
2728 ; CHECK: (setlocal @2 (fsub @1 @0))
2829 define float @fsub32(float %x, float %y) {
2930 %a = fsub float %x, %y
3031 ret float %a
3132 }
3233
33 ; CHECK-LABEL: fmul32:
34 ; CHECK-LABEL: (func $fmul32
3435 ; CHECK: (setlocal @2 (fmul @1 @0))
3536 define float @fmul32(float %x, float %y) {
3637 %a = fmul float %x, %y
3738 ret float %a
3839 }
3940
40 ; CHECK-LABEL: fdiv32:
41 ; CHECK-LABEL: (func $fdiv32
4142 ; CHECK: (setlocal @2 (fdiv @1 @0))
4243 define float @fdiv32(float %x, float %y) {
4344 %a = fdiv float %x, %y
4445 ret float %a
4546 }
4647
47 ; CHECK-LABEL: fabs32:
48 ; CHECK-LABEL: (func $fabs32
4849 ; CHECK: (setlocal @1 (fabs @0))
4950 define float @fabs32(float %x) {
5051 %a = call float @llvm.fabs.f32(float %x)
5152 ret float %a
5253 }
5354
54 ; CHECK-LABEL: fneg32:
55 ; CHECK-LABEL: (func $fneg32
5556 ; CHECK: (setlocal @1 (fneg @0))
5657 define float @fneg32(float %x) {
5758 %a = fsub float -0., %x
5859 ret float %a
5960 }
6061
61 ; CHECK-LABEL: copysign32:
62 ; CHECK-LABEL: (func $copysign32
6263 ; CHECK: (setlocal @2 (copysign @1 @0))
6364 define float @copysign32(float %x, float %y) {
6465 %a = call float @llvm.copysign.f32(float %x, float %y)
6566 ret float %a
6667 }
6768
68 ; CHECK-LABEL: sqrt32:
69 ; CHECK-LABEL: (func $sqrt32
6970 ; CHECK: (setlocal @1 (sqrt @0))
7071 define float @sqrt32(float %x) {
7172 %a = call float @llvm.sqrt.f32(float %x)
7273 ret float %a
7374 }
7475
75 ; CHECK-LABEL: ceil32:
76 ; CHECK-LABEL: (func $ceil32
7677 ; CHECK: (setlocal @1 (ceil @0))
7778 define float @ceil32(float %x) {
7879 %a = call float @llvm.ceil.f32(float %x)
7980 ret float %a
8081 }
8182
82 ; CHECK-LABEL: floor32:
83 ; CHECK-LABEL: (func $floor32
8384 ; CHECK: (setlocal @1 (floor @0))
8485 define float @floor32(float %x) {
8586 %a = call float @llvm.floor.f32(float %x)
8687 ret float %a
8788 }
8889
89 ; CHECK-LABEL: trunc32:
90 ; CHECK-LABEL: (func $trunc32
9091 ; CHECK: (setlocal @1 (trunc @0))
9192 define float @trunc32(float %x) {
9293 %a = call float @llvm.trunc.f32(float %x)
9394 ret float %a
9495 }
9596
96 ; CHECK-LABEL: nearestint32:
97 ; CHECK-LABEL: (func $nearestint32
9798 ; CHECK: (setlocal @1 (nearestint @0))
9899 define float @nearestint32(float %x) {
99100 %a = call float @llvm.nearbyint.f32(float %x)
100101 ret float %a
101102 }
102103
103 ; CHECK-LABEL: nearestint32_via_rint:
104 ; CHECK-LABEL: (func $nearestint32_via_rint
104105 ; CHECK: (setlocal @1 (nearestint @0))
105106 define float @nearestint32_via_rint(float %x) {
106107 %a = call float @llvm.rint.f32(float %x)
1313 declare double @llvm.nearbyint.f64(double)
1414 declare double @llvm.rint.f64(double)
1515
16 ; CHECK-LABEL: fadd64:
16 ; CHECK-LABEL: (func $fadd64
17 ; CHECK-NEXT: (param f64) (param f64) (result f64)
1718 ; CHECK-NEXT: (setlocal @0 (argument 1))
1819 ; CHECK-NEXT: (setlocal @1 (argument 0))
1920 ; CHECK-NEXT: (setlocal @2 (fadd @1 @0))
2324 ret double %a
2425 }
2526
26 ; CHECK-LABEL: fsub64:
27 ; CHECK-LABEL: (func $fsub64
2728 ; CHECK: (setlocal @2 (fsub @1 @0))
2829 define double @fsub64(double %x, double %y) {
2930 %a = fsub double %x, %y
3031 ret double %a
3132 }
3233
33 ; CHECK-LABEL: fmul64:
34 ; CHECK-LABEL: (func $fmul64
3435 ; CHECK: (setlocal @2 (fmul @1 @0))
3536 define double @fmul64(double %x, double %y) {
3637 %a = fmul double %x, %y
3738 ret double %a
3839 }
3940
40 ; CHECK-LABEL: fdiv64:
41 ; CHECK-LABEL: (func $fdiv64
4142 ; CHECK: (setlocal @2 (fdiv @1 @0))
4243 define double @fdiv64(double %x, double %y) {
4344 %a = fdiv double %x, %y
4445 ret double %a
4546 }
4647
47 ; CHECK-LABEL: fabs64:
48 ; CHECK-LABEL: (func $fabs64
4849 ; CHECK: (setlocal @1 (fabs @0))
4950 define double @fabs64(double %x) {
5051 %a = call double @llvm.fabs.f64(double %x)
5152 ret double %a
5253 }
5354
54 ; CHECK-LABEL: fneg64:
55 ; CHECK-LABEL: (func $fneg64
5556 ; CHECK: (setlocal @1 (fneg @0))
5657 define double @fneg64(double %x) {
5758 %a = fsub double -0., %x
5859 ret double %a
5960 }
6061
61 ; CHECK-LABEL: copysign64:
62 ; CHECK-LABEL: (func $copysign64
6263 ; CHECK: (setlocal @2 (copysign @1 @0))
6364 define double @copysign64(double %x, double %y) {
6465 %a = call double @llvm.copysign.f64(double %x, double %y)
6566 ret double %a
6667 }
6768
68 ; CHECK-LABEL: sqrt64:
69 ; CHECK-LABEL: (func $sqrt64
6970 ; CHECK: (setlocal @1 (sqrt @0))
7071 define double @sqrt64(double %x) {
7172 %a = call double @llvm.sqrt.f64(double %x)
7273 ret double %a
7374 }
7475
75 ; CHECK-LABEL: ceil64:
76 ; CHECK-LABEL: (func $ceil64
7677 ; CHECK: (setlocal @1 (ceil @0))
7778 define double @ceil64(double %x) {
7879 %a = call double @llvm.ceil.f64(double %x)
7980 ret double %a
8081 }
8182
82 ; CHECK-LABEL: floor64:
83 ; CHECK-LABEL: (func $floor64
8384 ; CHECK: (setlocal @1 (floor @0))
8485 define double @floor64(double %x) {
8586 %a = call double @llvm.floor.f64(double %x)
8687 ret double %a
8788 }
8889
89 ; CHECK-LABEL: trunc64:
90 ; CHECK-LABEL: (func $trunc64
9091 ; CHECK: (setlocal @1 (trunc @0))
9192 define double @trunc64(double %x) {
9293 %a = call double @llvm.trunc.f64(double %x)
9394 ret double %a
9495 }
9596
96 ; CHECK-LABEL: nearestint64:
97 ; CHECK-LABEL: (func $nearestint64
9798 ; CHECK: (setlocal @1 (nearestint @0))
9899 define double @nearestint64(double %x) {
99100 %a = call double @llvm.nearbyint.f64(double %x)
100101 ret double %a
101102 }
102103
103 ; CHECK-LABEL: nearestint64_via_rint:
104 ; CHECK-LABEL: (func $nearestint64_via_rint
104105 ; CHECK: (setlocal @1 (nearestint @0))
105106 define double @nearestint64_via_rint(double %x) {
106107 %a = call double @llvm.rint.f64(double %x)
0 ; RUN: llc < %s -asm-verbose=false | FileCheck %s
1
2 ; Test that basic functions assemble as expected.
3
4 target datalayout = "e-p:32:32-i64:64-v128:8:128-n32:64-S128"
5 target triple = "wasm32-unknown-unknown"
6
7 ; CHECK-LABEL: (func $f0{{$}}
8 ; CHECK: (return){{$}}
9 ; CHECK-NEXT: ) ;; end func $f0{{$}}
10 define void @f0() {
11 ret void
12 }
13
14 ; CHECK-LABEL: (func $f1{{$}}
15 ; CHECK-NEXT: (result i32){{$}}
16 ; CHECK-NEXT: (setlocal @0 (immediate 0)){{$}}
17 ; CHECK-NEXT: (return @0){{$}}
18 ; CHECK-NEXT: ) ;; end func $f1{{$}}
19 define i32 @f1() {
20 ret i32 0
21 }
22
23 ; CHECK-LABEL: (func $f2{{$}}
24 ; CHECK-NEXT: (param i32) (param f32) (result i32){{$}}
25 ; CHECK-NEXT: (setlocal @0 (immediate 0)){{$}}
26 ; CHECK-NEXT: (return @0){{$}}
27 ; CHECK-NEXT: ) ;; end func $f2{{$}}
28 define i32 @f2(i32 %p1, float %p2) {
29 ret i32 0
30 }
31
32 ; CHECK-LABEL: (func $f3{{$}}
33 ; CHECK-NEXT: (param i32) (param f32){{$}}
34 ; CHECK-NEXT: (return){{$}}
35 ; CHECK-NEXT: ) ;; end func $f3{{$}}
36 define void @f3(i32 %p1, float %p2) {
37 ret void
38 }
77 ; CHECK-NOT: globl
88 ; CHECK: ;; .globl foo
99 ; CHECK-NOT: globl
10 ; CHECK-LABEL: foo:
10 ; CHECK-LABEL: (func $foo
1111 define void @foo() {
1212 ret void
1313 }
44 target datalayout = "e-p:32:32-i64:64-n32:64-S128"
55 target triple = "wasm32-unknown-unknown"
66
7 ; CHECK-LABEL: zero_i32:
7 ; CHECK-LABEL: (func $zero_i32
8 ; CHECK-NEXT: (result i32)
89 ; CHECK-NEXT: (setlocal @0 (immediate 0))
910 ; CHECK-NEXT: (return @0)
1011 define i32 @zero_i32() {
1112 ret i32 0
1213 }
1314
14 ; CHECK-LABEL: one_i32:
15 ; CHECK-LABEL: (func $one_i32
16 ; CHECK-NEXT: (result i32)
1517 ; CHECK-NEXT: (setlocal @0 (immediate 1))
1618 ; CHECK-NEXT: (return @0)
1719 define i32 @one_i32() {
1820 ret i32 1
1921 }
2022
21 ; CHECK-LABEL: max_i32:
23 ; CHECK-LABEL: (func $max_i32
24 ; CHECK-NEXT: (result i32)
2225 ; CHECK-NEXT: (setlocal @0 (immediate 2147483647))
2326 ; CHECK-NEXT: (return @0)
2427 define i32 @max_i32() {
2528 ret i32 2147483647
2629 }
2730
28 ; CHECK-LABEL: min_i32:
31 ; CHECK-LABEL: (func $min_i32
32 ; CHECK-NEXT: (result i32)
2933 ; CHECK-NEXT: (setlocal @0 (immediate -2147483648))
3034 ; CHECK-NEXT: (return @0)
3135 define i32 @min_i32() {
3236 ret i32 -2147483648
3337 }
3438
35 ; CHECK-LABEL: zero_i64:
39 ; CHECK-LABEL: (func $zero_i64
40 ; CHECK-NEXT: (result i64)
3641 ; CHECK-NEXT: (setlocal @0 (immediate 0))
3742 ; CHECK-NEXT: (return @0)
3843 define i64 @zero_i64() {
3944 ret i64 0
4045 }
4146
42 ; CHECK-LABEL: one_i64:
47 ; CHECK-LABEL: (func $one_i64
48 ; CHECK-NEXT: (result i64)
4349 ; CHECK-NEXT: (setlocal @0 (immediate 1))
4450 ; CHECK-NEXT: (return @0)
4551 define i64 @one_i64() {
4652 ret i64 1
4753 }
4854
49 ; CHECK-LABEL: max_i64:
55 ; CHECK-LABEL: (func $max_i64
56 ; CHECK-NEXT: (result i64)
5057 ; CHECK-NEXT: (setlocal @0 (immediate 9223372036854775807))
5158 ; CHECK-NEXT: (return @0)
5259 define i64 @max_i64() {
5360 ret i64 9223372036854775807
5461 }
5562
56 ; CHECK-LABEL: min_i64:
63 ; CHECK-LABEL: (func $min_i64
64 ; CHECK-NEXT: (result i64)
5765 ; CHECK-NEXT: (setlocal @0 (immediate -9223372036854775808))
5866 ; CHECK-NEXT: (return @0)
5967 define i64 @min_i64() {
6068 ret i64 -9223372036854775808
6169 }
6270
63 ; CHECK-LABEL: negzero_f32:
71 ; CHECK-LABEL: (func $negzero_f32
72 ; CHECK-NEXT: (result f32)
6473 ; CHECK-NEXT: (setlocal @0 (immediate -0x0p0))
6574 ; CHECK-NEXT: (return @0)
6675 define float @negzero_f32() {
6776 ret float -0.0
6877 }
6978
70 ; CHECK-LABEL: zero_f32:
79 ; CHECK-LABEL: (func $zero_f32
80 ; CHECK-NEXT: (result f32)
7181 ; CHECK-NEXT: (setlocal @0 (immediate 0x0p0))
7282 ; CHECK-NEXT: (return @0)
7383 define float @zero_f32() {
7484 ret float 0.0
7585 }
7686
77 ; CHECK-LABEL: one_f32:
87 ; CHECK-LABEL: (func $one_f32
88 ; CHECK-NEXT: (result f32)
7889 ; CHECK-NEXT: (setlocal @0 (immediate 0x1p0))
7990 ; CHECK-NEXT: (return @0)
8091 define float @one_f32() {
8192 ret float 1.0
8293 }
8394
84 ; CHECK-LABEL: two_f32:
95 ; CHECK-LABEL: (func $two_f32
96 ; CHECK-NEXT: (result f32)
8597 ; CHECK-NEXT: (setlocal @0 (immediate 0x1p1))
8698 ; CHECK-NEXT: (return @0)
8799 define float @two_f32() {
88100 ret float 2.0
89101 }
90102
91 ; CHECK-LABEL: nan_f32:
103 ; CHECK-LABEL: (func $nan_f32
104 ; CHECK-NEXT: (result f32)
92105 ; CHECK-NEXT: (setlocal @0 (immediate nan))
93106 ; CHECK-NEXT: (return @0)
94107 define float @nan_f32() {
95108 ret float 0x7FF8000000000000
96109 }
97110
98 ; CHECK-LABEL: negnan_f32:
111 ; CHECK-LABEL: (func $negnan_f32
112 ; CHECK-NEXT: (result f32)
99113 ; CHECK-NEXT: (setlocal @0 (immediate -nan))
100114 ; CHECK-NEXT: (return @0)
101115 define float @negnan_f32() {
102116 ret float 0xFFF8000000000000
103117 }
104118
105 ; CHECK-LABEL: inf_f32:
119 ; CHECK-LABEL: (func $inf_f32
120 ; CHECK-NEXT: (result f32)
106121 ; CHECK-NEXT: (setlocal @0 (immediate infinity))
107122 ; CHECK-NEXT: (return @0)
108123 define float @inf_f32() {
109124 ret float 0x7FF0000000000000
110125 }
111126
112 ; CHECK-LABEL: neginf_f32:
127 ; CHECK-LABEL: (func $neginf_f32
128 ; CHECK-NEXT: (result f32)
113129 ; CHECK-NEXT: (setlocal @0 (immediate -infinity))
114130 ; CHECK-NEXT: (return @0)
115131 define float @neginf_f32() {
116132 ret float 0xFFF0000000000000
117133 }
118134
119 ; CHECK-LABEL: negzero_f64:
135 ; CHECK-LABEL: (func $negzero_f64
136 ; CHECK-NEXT: (result f64)
120137 ; CHECK-NEXT: (setlocal @0 (immediate -0x0p0))
121138 ; CHECK-NEXT: (return @0)
122139 define double @negzero_f64() {
123140 ret double -0.0
124141 }
125142
126 ; CHECK-LABEL: zero_f64:
143 ; CHECK-LABEL: (func $zero_f64
144 ; CHECK-NEXT: (result f64)
127145 ; CHECK-NEXT: (setlocal @0 (immediate 0x0p0))
128146 ; CHECK-NEXT: (return @0)
129147 define double @zero_f64() {
130148 ret double 0.0
131149 }
132150
133 ; CHECK-LABEL: one_f64:
151 ; CHECK-LABEL: (func $one_f64
152 ; CHECK-NEXT: (result f64)
134153 ; CHECK-NEXT: (setlocal @0 (immediate 0x1p0))
135154 ; CHECK-NEXT: (return @0)
136155 define double @one_f64() {
137156 ret double 1.0
138157 }
139158
140 ; CHECK-LABEL: two_f64:
159 ; CHECK-LABEL: (func $two_f64
160 ; CHECK-NEXT: (result f64)
141161 ; CHECK-NEXT: (setlocal @0 (immediate 0x1p1))
142162 ; CHECK-NEXT: (return @0)
143163 define double @two_f64() {
144164 ret double 2.0
145165 }
146166
147 ; CHECK-LABEL: nan_f64:
167 ; CHECK-LABEL: (func $nan_f64
168 ; CHECK-NEXT: (result f64)
148169 ; CHECK-NEXT: (setlocal @0 (immediate nan))
149170 ; CHECK-NEXT: (return @0)
150171 define double @nan_f64() {
151172 ret double 0x7FF8000000000000
152173 }
153174
154 ; CHECK-LABEL: negnan_f64:
175 ; CHECK-LABEL: (func $negnan_f64
176 ; CHECK-NEXT: (result f64)
155177 ; CHECK-NEXT: (setlocal @0 (immediate -nan))
156178 ; CHECK-NEXT: (return @0)
157179 define double @negnan_f64() {
158180 ret double 0xFFF8000000000000
159181 }
160182
161 ; CHECK-LABEL: inf_f64:
183 ; CHECK-LABEL: (func $inf_f64
184 ; CHECK-NEXT: (result f64)
162185 ; CHECK-NEXT: (setlocal @0 (immediate infinity))
163186 ; CHECK-NEXT: (return @0)
164187 define double @inf_f64() {
165188 ret double 0x7FF0000000000000
166189 }
167190
168 ; CHECK-LABEL: neginf_f64:
191 ; CHECK-LABEL: (func $neginf_f64
192 ; CHECK-NEXT: (result f64)
169193 ; CHECK-NEXT: (setlocal @0 (immediate -infinity))
170194 ; CHECK-NEXT: (return @0)
171195 define double @neginf_f64() {
88 declare i32 @llvm.cttz.i32(i32, i1)
99 declare i32 @llvm.ctpop.i32(i32)
1010
11 ; CHECK-LABEL: add32:
11 ; CHECK-LABEL: (func $add32
12 ; CHECK-NEXT: (param i32) (param i32) (result i32)
1213 ; CHECK-NEXT: (setlocal @0 (argument 1))
1314 ; CHECK-NEXT: (setlocal @1 (argument 0))
1415 ; CHECK-NEXT: (setlocal @2 (add @1 @0))
1819 ret i32 %a
1920 }
2021
21 ; CHECK-LABEL: sub32:
22 ; CHECK-LABEL: (func $sub32
23 ; CHECK-NEXT: (param i32) (param i32) (result i32)
2224 ; CHECK-NEXT: (setlocal @0 (argument 1))
2325 ; CHECK-NEXT: (setlocal @1 (argument 0))
2426 ; CHECK-NEXT: (setlocal @2 (sub @1 @0))
2830 ret i32 %a
2931 }
3032
31 ; CHECK-LABEL: mul32:
33 ; CHECK-LABEL: (func $mul32
34 ; CHECK-NEXT: (param i32) (param i32) (result i32)
3235 ; CHECK-NEXT: (setlocal @0 (argument 1))
3336 ; CHECK-NEXT: (setlocal @1 (argument 0))
3437 ; CHECK-NEXT: (setlocal @2 (mul @1 @0))
3841 ret i32 %a
3942 }
4043
41 ; CHECK-LABEL: sdiv32:
44 ; CHECK-LABEL: (func $sdiv32
45 ; CHECK-NEXT: (param i32) (param i32) (result i32)
4246 ; CHECK-NEXT: (setlocal @0 (argument 1))
4347 ; CHECK-NEXT: (setlocal @1 (argument 0))
4448 ; CHECK-NEXT: (setlocal @2 (sdiv @1 @0))
4852 ret i32 %a
4953 }
5054
51 ; CHECK-LABEL: udiv32:
55 ; CHECK-LABEL: (func $udiv32
56 ; CHECK-NEXT: (param i32) (param i32) (result i32)
5257 ; CHECK-NEXT: (setlocal @0 (argument 1))
5358 ; CHECK-NEXT: (setlocal @1 (argument 0))
5459 ; CHECK-NEXT: (setlocal @2 (udiv @1 @0))
5863 ret i32 %a
5964 }
6065
61 ; CHECK-LABEL: srem32:
66 ; CHECK-LABEL: (func $srem32
67 ; CHECK-NEXT: (param i32) (param i32) (result i32)
6268 ; CHECK-NEXT: (setlocal @0 (argument 1))
6369 ; CHECK-NEXT: (setlocal @1 (argument 0))
6470 ; CHECK-NEXT: (setlocal @2 (srem @1 @0))
6874 ret i32 %a
6975 }
7076
71 ; CHECK-LABEL: urem32:
77 ; CHECK-LABEL: (func $urem32
78 ; CHECK-NEXT: (param i32) (param i32) (result i32)
7279 ; CHECK-NEXT: (setlocal @0 (argument 1))
7380 ; CHECK-NEXT: (setlocal @1 (argument 0))
7481 ; CHECK-NEXT: (setlocal @2 (urem @1 @0))
7885 ret i32 %a
7986 }
8087
81 ; CHECK-LABEL: and32:
88 ; CHECK-LABEL: (func $and32
89 ; CHECK-NEXT: (param i32) (param i32) (result i32)
8290 ; CHECK-NEXT: (setlocal @0 (argument 1))
8391 ; CHECK-NEXT: (setlocal @1 (argument 0))
8492 ; CHECK-NEXT: (setlocal @2 (and @1 @0))
8896 ret i32 %a
8997 }
9098
91 ; CHECK-LABEL: ior32:
99 ; CHECK-LABEL: (func $ior32
100 ; CHECK-NEXT: (param i32) (param i32) (result i32)
92101 ; CHECK-NEXT: (setlocal @0 (argument 1))
93102 ; CHECK-NEXT: (setlocal @1 (argument 0))
94103 ; CHECK-NEXT: (setlocal @2 (ior @1 @0))
98107 ret i32 %a
99108 }
100109
101 ; CHECK-LABEL: xor32:
110 ; CHECK-LABEL: (func $xor32
111 ; CHECK-NEXT: (param i32) (param i32) (result i32)
102112 ; CHECK-NEXT: (setlocal @0 (argument 1))
103113 ; CHECK-NEXT: (setlocal @1 (argument 0))
104114 ; CHECK-NEXT: (setlocal @2 (xor @1 @0))
108118 ret i32 %a
109119 }
110120
111 ; CHECK-LABEL: shl32:
121 ; CHECK-LABEL: (func $shl32
122 ; CHECK-NEXT: (param i32) (param i32) (result i32)
112123 ; CHECK-NEXT: (setlocal @0 (argument 1))
113124 ; CHECK-NEXT: (setlocal @1 (argument 0))
114125 ; CHECK-NEXT: (setlocal @2 (shl @1 @0))
118129 ret i32 %a
119130 }
120131
121 ; CHECK-LABEL: shr32:
132 ; CHECK-LABEL: (func $shr32
133 ; CHECK-NEXT: (param i32) (param i32) (result i32)
122134 ; CHECK-NEXT: (setlocal @0 (argument 1))
123135 ; CHECK-NEXT: (setlocal @1 (argument 0))
124136 ; CHECK-NEXT: (setlocal @2 (shr @1 @0))
128140 ret i32 %a
129141 }
130142
131 ; CHECK-LABEL: sar32:
143 ; CHECK-LABEL: (func $sar32
144 ; CHECK-NEXT: (param i32) (param i32) (result i32)
132145 ; CHECK-NEXT: (setlocal @0 (argument 1))
133146 ; CHECK-NEXT: (setlocal @1 (argument 0))
134147 ; CHECK-NEXT: (setlocal @2 (sar @1 @0))
138151 ret i32 %a
139152 }
140153
141 ; CHECK-LABEL: clz32:
154 ; CHECK-LABEL: (func $clz32
155 ; CHECK-NEXT: (param i32) (result i32)
142156 ; CHECK-NEXT: (setlocal @0 (argument 0))
143157 ; CHECK-NEXT: (setlocal @1 (clz @0))
144158 ; CHECK-NEXT: (return @1)
147161 ret i32 %a
148162 }
149163
150 ; CHECK-LABEL: clz32_zero_undef:
164 ; CHECK-LABEL: (func $clz32_zero_undef
165 ; CHECK-NEXT: (param i32) (result i32)
151166 ; CHECK-NEXT: (setlocal @0 (argument 0))
152167 ; CHECK-NEXT: (setlocal @1 (clz @0))
153168 ; CHECK-NEXT: (return @1)
156171 ret i32 %a
157172 }
158173
159 ; CHECK-LABEL: ctz32:
174 ; CHECK-LABEL: (func $ctz32
175 ; CHECK-NEXT: (param i32) (result i32)
160176 ; CHECK-NEXT: (setlocal @0 (argument 0))
161177 ; CHECK-NEXT: (setlocal @1 (ctz @0))
162178 ; CHECK-NEXT: (return @1)
165181 ret i32 %a
166182 }
167183
168 ; CHECK-LABEL: ctz32_zero_undef:
184 ; CHECK-LABEL: (func $ctz32_zero_undef
185 ; CHECK-NEXT: (param i32) (result i32)
169186 ; CHECK-NEXT: (setlocal @0 (argument 0))
170187 ; CHECK-NEXT: (setlocal @1 (ctz @0))
171188 ; CHECK-NEXT: (return @1)
174191 ret i32 %a
175192 }
176193
177 ; CHECK-LABEL: popcnt32:
194 ; CHECK-LABEL: (func $popcnt32
195 ; CHECK-NEXT: (param i32) (result i32)
178196 ; CHECK-NEXT: (setlocal @0 (argument 0))
179197 ; CHECK-NEXT: (setlocal @1 (popcnt @0))
180198 ; CHECK-NEXT: (return @1)
88 declare i64 @llvm.cttz.i64(i64, i1)
99 declare i64 @llvm.ctpop.i64(i64)
1010
11 ; CHECK-LABEL: add64:
11 ; CHECK-LABEL: (func $add64
12 ; CHECK-NEXT: (param i64) (param i64) (result i64)
1213 ; CHECK-NEXT: (setlocal @0 (argument 1))
1314 ; CHECK-NEXT: (setlocal @1 (argument 0))
1415 ; CHECK-NEXT: (setlocal @2 (add @1 @0))
1819 ret i64 %a
1920 }
2021
21 ; CHECK-LABEL: sub64:
22 ; CHECK-LABEL: (func $sub64
23 ; CHECK-NEXT: (param i64) (param i64) (result i64)
2224 ; CHECK-NEXT: (setlocal @0 (argument 1))
2325 ; CHECK-NEXT: (setlocal @1 (argument 0))
2426 ; CHECK-NEXT: (setlocal @2 (sub @1 @0))
2830 ret i64 %a
2931 }
3032
31 ; CHECK-LABEL: mul64:
33 ; CHECK-LABEL: (func $mul64
34 ; CHECK-NEXT: (param i64) (param i64) (result i64)
3235 ; CHECK-NEXT: (setlocal @0 (argument 1))
3336 ; CHECK-NEXT: (setlocal @1 (argument 0))
3437 ; CHECK-NEXT: (setlocal @2 (mul @1 @0))
3841 ret i64 %a
3942 }
4043
41 ; CHECK-LABEL: sdiv64:
44 ; CHECK-LABEL: (func $sdiv64
45 ; CHECK-NEXT: (param i64) (param i64) (result i64)
4246 ; CHECK-NEXT: (setlocal @0 (argument 1))
4347 ; CHECK-NEXT: (setlocal @1 (argument 0))
4448 ; CHECK-NEXT: (setlocal @2 (sdiv @1 @0))
4852 ret i64 %a
4953 }
5054
51 ; CHECK-LABEL: udiv64:
55 ; CHECK-LABEL: (func $udiv64
56 ; CHECK-NEXT: (param i64) (param i64) (result i64)
5257 ; CHECK-NEXT: (setlocal @0 (argument 1))
5358 ; CHECK-NEXT: (setlocal @1 (argument 0))
5459 ; CHECK-NEXT: (setlocal @2 (udiv @1 @0))
5863 ret i64 %a
5964 }
6065
61 ; CHECK-LABEL: srem64:
66 ; CHECK-LABEL: (func $srem64
67 ; CHECK-NEXT: (param i64) (param i64) (result i64)
6268 ; CHECK-NEXT: (setlocal @0 (argument 1))
6369 ; CHECK-NEXT: (setlocal @1 (argument 0))
6470 ; CHECK-NEXT: (setlocal @2 (srem @1 @0))
6874 ret i64 %a
6975 }
7076
71 ; CHECK-LABEL: urem64:
77 ; CHECK-LABEL: (func $urem64
78 ; CHECK-NEXT: (param i64) (param i64) (result i64)
7279 ; CHECK-NEXT: (setlocal @0 (argument 1))
7380 ; CHECK-NEXT: (setlocal @1 (argument 0))
7481 ; CHECK-NEXT: (setlocal @2 (urem @1 @0))
7885 ret i64 %a
7986 }
8087
81 ; CHECK-LABEL: and64:
88 ; CHECK-LABEL: (func $and64
89 ; CHECK-NEXT: (param i64) (param i64) (result i64)
8290 ; CHECK-NEXT: (setlocal @0 (argument 1))
8391 ; CHECK-NEXT: (setlocal @1 (argument 0))
8492 ; CHECK-NEXT: (setlocal @2 (and @1 @0))
8896 ret i64 %a
8997 }
9098
91 ; CHECK-LABEL: ior64:
99 ; CHECK-LABEL: (func $ior64
100 ; CHECK-NEXT: (param i64) (param i64) (result i64)
92101 ; CHECK-NEXT: (setlocal @0 (argument 1))
93102 ; CHECK-NEXT: (setlocal @1 (argument 0))
94103 ; CHECK-NEXT: (setlocal @2 (ior @1 @0))
98107 ret i64 %a
99108 }
100109
101 ; CHECK-LABEL: xor64:
110 ; CHECK-LABEL: (func $xor64
111 ; CHECK-NEXT: (param i64) (param i64) (result i64)
102112 ; CHECK-NEXT: (setlocal @0 (argument 1))
103113 ; CHECK-NEXT: (setlocal @1 (argument 0))
104114 ; CHECK-NEXT: (setlocal @2 (xor @1 @0))
108118 ret i64 %a
109119 }
110120
111 ; CHECK-LABEL: shl64:
121 ; CHECK-LABEL: (func $shl64
122 ; CHECK-NEXT: (param i64) (param i64) (result i64)
112123 ; CHECK-NEXT: (setlocal @0 (argument 1))
113124 ; CHECK-NEXT: (setlocal @1 (argument 0))
114125 ; CHECK-NEXT: (setlocal @2 (shl @1 @0))
118129 ret i64 %a
119130 }
120131
121 ; CHECK-LABEL: shr64:
132 ; CHECK-LABEL: (func $shr64
133 ; CHECK-NEXT: (param i64) (param i64) (result i64)
122134 ; CHECK-NEXT: (setlocal @0 (argument 1))
123135 ; CHECK-NEXT: (setlocal @1 (argument 0))
124136 ; CHECK-NEXT: (setlocal @2 (shr @1 @0))
128140 ret i64 %a
129141 }
130142
131 ; CHECK-LABEL: sar64:
143 ; CHECK-LABEL: (func $sar64
144 ; CHECK-NEXT: (param i64) (param i64) (result i64)
132145 ; CHECK-NEXT: (setlocal @0 (argument 1))
133146 ; CHECK-NEXT: (setlocal @1 (argument 0))
134147 ; CHECK-NEXT: (setlocal @2 (sar @1 @0))
138151 ret i64 %a
139152 }
140153
141 ; CHECK-LABEL: clz64:
154 ; CHECK-LABEL: (func $clz64
155 ; CHECK-NEXT: (param i64) (result i64)
142156 ; CHECK-NEXT: (setlocal @0 (argument 0))
143157 ; CHECK-NEXT: (setlocal @1 (clz @0))
144158 ; CHECK-NEXT: (return @1)
147161 ret i64 %a
148162 }
149163
150 ; CHECK-LABEL: clz64_zero_undef:
164 ; CHECK-LABEL: (func $clz64_zero_undef
165 ; CHECK-NEXT: (param i64) (result i64)
151166 ; CHECK-NEXT: (setlocal @0 (argument 0))
152167 ; CHECK-NEXT: (setlocal @1 (clz @0))
153168 ; CHECK-NEXT: (return @1)
156171 ret i64 %a
157172 }
158173
159 ; CHECK-LABEL: ctz64:
174 ; CHECK-LABEL: (func $ctz64
175 ; CHECK-NEXT: (param i64) (result i64)
160176 ; CHECK-NEXT: (setlocal @0 (argument 0))
161177 ; CHECK-NEXT: (setlocal @1 (ctz @0))
162178 ; CHECK-NEXT: (return @1)
165181 ret i64 %a
166182 }
167183
168 ; CHECK-LABEL: ctz64_zero_undef:
184 ; CHECK-LABEL: (func $ctz64_zero_undef
185 ; CHECK-NEXT: (param i64) (result i64)
169186 ; CHECK-NEXT: (setlocal @0 (argument 0))
170187 ; CHECK-NEXT: (setlocal @1 (ctz @0))
171188 ; CHECK-NEXT: (return @1)
174191 ret i64 %a
175192 }
176193
177 ; CHECK-LABEL: popcnt64:
194 ; CHECK-LABEL: (func $popcnt64
195 ; CHECK-NEXT: (param i64) (result i64)
178196 ; CHECK-NEXT: (setlocal @0 (argument 0))
179197 ; CHECK-NEXT: (setlocal @1 (popcnt @0))
180198 ; CHECK-NEXT: (return @1)
66
77 declare i32 @llvm.wasm.page.size.i32() nounwind readnone
88
9 ; CHECK-LABEL: page_size:
9 ; CHECK-LABEL: (func $page_size
10 ; CHECK-NEXT: (result i32)
1011 ; CHECK-NEXT: (setlocal @0 (page_size))
1112 ; CHECK-NEXT: (return @0)
1213 define i32 @page_size() {
66
77 declare i64 @llvm.wasm.page.size.i64() nounwind readnone
88
9 ; CHECK-LABEL: page_size:
9 ; CHECK-LABEL: (func $page_size
10 ; CHECK-NEXT: (result i64)
1011 ; CHECK-NEXT: (setlocal @0 (page_size))
1112 ; CHECK-NEXT: (return @0)
1213 define i64 @page_size() {
22 target datalayout = "e-p:32:32-i64:64-n32:64-S128"
33 target triple = "wasm32-unknown-unknown"
44
5 ; CHECK-LABEL: return_void:
6 ; CHECK-NEXT: (return)
5 ; CHECK-LABEL: (func $return_void
6 ; CHECK: (return)
77 define void @return_void() {
88 ret void
99 }
44 target datalayout = "e-p:32:32-i64:64-n32:64-S128"
55 target triple = "wasm32-unknown-unknown"
66
7 ; CHECK-LABEL: unused_first:
7 ; CHECK-LABEL: (func $unused_first
8 ; CHECK-NEXT: (param i32) (param i32) (result i32)
89 ; CHECK-NEXT: (setlocal @0 (argument 1))
910 ; CHECK-NEXT: (return @0)
1011 define i32 @unused_first(i32 %x, i32 %y) {
1112 ret i32 %y
1213 }
1314
14 ; CHECK-LABEL: unused_second:
15 ; CHECK-LABEL: (func $unused_second
16 ; CHECK-NEXT: (param i32) (param i32) (result i32)
1517 ; CHECK-NEXT: (setlocal @0 (argument 0))
1618 ; CHECK-NEXT: (return @0)
1719 define i32 @unused_second(i32 %x, i32 %y) {