Wouter van Oortmerssen | 8a9cb24 | 2018-08-27 15:45:51 +0000 | [diff] [blame] | 1 | ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers | FileCheck %s |
JF Bastien | ef172fc | 2015-08-11 02:45:15 +0000 | [diff] [blame] | 2 | |
| 3 | ; Test that basic 32-bit floating-point operations assemble as expected. |
| 4 | |
Dan Gohman | 0c6f5ac | 2016-01-07 03:19:23 +0000 | [diff] [blame] | 5 | target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" |
Sam Clegg | a590800 | 2018-05-10 17:49:11 +0000 | [diff] [blame] | 6 | target triple = "wasm32-unknown-unknown" |
JF Bastien | ef172fc | 2015-08-11 02:45:15 +0000 | [diff] [blame] | 7 | |
| 8 | declare float @llvm.fabs.f32(float) |
| 9 | declare float @llvm.copysign.f32(float, float) |
| 10 | declare float @llvm.sqrt.f32(float) |
Dan Gohman | 896e53f | 2015-08-24 18:23:13 +0000 | [diff] [blame] | 11 | declare float @llvm.ceil.f32(float) |
| 12 | declare float @llvm.floor.f32(float) |
| 13 | declare float @llvm.trunc.f32(float) |
| 14 | declare float @llvm.nearbyint.f32(float) |
| 15 | declare float @llvm.rint.f32(float) |
Dan Gohman | 9341c1d | 2015-12-10 04:52:33 +0000 | [diff] [blame] | 16 | declare float @llvm.fma.f32(float, float, float) |
JF Bastien | ef172fc | 2015-08-11 02:45:15 +0000 | [diff] [blame] | 17 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 18 | ; CHECK-LABEL: fadd32: |
Wouter van Oortmerssen | 49482f8 | 2018-11-19 17:10:36 +0000 | [diff] [blame] | 19 | ; CHECK-NEXT: .functype fadd32 (f32, f32) -> (f32){{$}} |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 20 | ; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}} |
| 21 | ; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}} |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 22 | ; CHECK-NEXT: f32.add $push[[LR:[0-9]+]]=, $pop[[L0]], $pop[[L1]]{{$}} |
| 23 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
JF Bastien | ef172fc | 2015-08-11 02:45:15 +0000 | [diff] [blame] | 24 | define float @fadd32(float %x, float %y) { |
| 25 | %a = fadd float %x, %y |
| 26 | ret float %a |
| 27 | } |
| 28 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 29 | ; CHECK-LABEL: fsub32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 30 | ; CHECK: f32.sub $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}} |
| 31 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
JF Bastien | ef172fc | 2015-08-11 02:45:15 +0000 | [diff] [blame] | 32 | define float @fsub32(float %x, float %y) { |
| 33 | %a = fsub float %x, %y |
| 34 | ret float %a |
| 35 | } |
| 36 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 37 | ; CHECK-LABEL: fmul32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 38 | ; CHECK: f32.mul $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}} |
| 39 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
JF Bastien | ef172fc | 2015-08-11 02:45:15 +0000 | [diff] [blame] | 40 | define float @fmul32(float %x, float %y) { |
| 41 | %a = fmul float %x, %y |
| 42 | ret float %a |
| 43 | } |
| 44 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 45 | ; CHECK-LABEL: fdiv32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 46 | ; CHECK: f32.div $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}} |
| 47 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
JF Bastien | ef172fc | 2015-08-11 02:45:15 +0000 | [diff] [blame] | 48 | define float @fdiv32(float %x, float %y) { |
| 49 | %a = fdiv float %x, %y |
| 50 | ret float %a |
| 51 | } |
| 52 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 53 | ; CHECK-LABEL: fabs32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 54 | ; CHECK: f32.abs $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} |
| 55 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
JF Bastien | ef172fc | 2015-08-11 02:45:15 +0000 | [diff] [blame] | 56 | define float @fabs32(float %x) { |
| 57 | %a = call float @llvm.fabs.f32(float %x) |
| 58 | ret float %a |
| 59 | } |
| 60 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 61 | ; CHECK-LABEL: fneg32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 62 | ; CHECK: f32.neg $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} |
| 63 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
JF Bastien | ef172fc | 2015-08-11 02:45:15 +0000 | [diff] [blame] | 64 | define float @fneg32(float %x) { |
| 65 | %a = fsub float -0., %x |
| 66 | ret float %a |
| 67 | } |
| 68 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 69 | ; CHECK-LABEL: copysign32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 70 | ; CHECK: f32.copysign $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}} |
| 71 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
JF Bastien | ef172fc | 2015-08-11 02:45:15 +0000 | [diff] [blame] | 72 | define float @copysign32(float %x, float %y) { |
| 73 | %a = call float @llvm.copysign.f32(float %x, float %y) |
| 74 | ret float %a |
| 75 | } |
| 76 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 77 | ; CHECK-LABEL: sqrt32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 78 | ; CHECK: f32.sqrt $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} |
| 79 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
JF Bastien | ef172fc | 2015-08-11 02:45:15 +0000 | [diff] [blame] | 80 | define float @sqrt32(float %x) { |
| 81 | %a = call float @llvm.sqrt.f32(float %x) |
| 82 | ret float %a |
| 83 | } |
Dan Gohman | 896e53f | 2015-08-24 18:23:13 +0000 | [diff] [blame] | 84 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 85 | ; CHECK-LABEL: ceil32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 86 | ; CHECK: f32.ceil $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} |
| 87 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
Dan Gohman | 896e53f | 2015-08-24 18:23:13 +0000 | [diff] [blame] | 88 | define float @ceil32(float %x) { |
| 89 | %a = call float @llvm.ceil.f32(float %x) |
| 90 | ret float %a |
| 91 | } |
| 92 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 93 | ; CHECK-LABEL: floor32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 94 | ; CHECK: f32.floor $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} |
| 95 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
Dan Gohman | 896e53f | 2015-08-24 18:23:13 +0000 | [diff] [blame] | 96 | define float @floor32(float %x) { |
| 97 | %a = call float @llvm.floor.f32(float %x) |
| 98 | ret float %a |
| 99 | } |
| 100 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 101 | ; CHECK-LABEL: trunc32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 102 | ; CHECK: f32.trunc $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} |
| 103 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
Dan Gohman | 896e53f | 2015-08-24 18:23:13 +0000 | [diff] [blame] | 104 | define float @trunc32(float %x) { |
| 105 | %a = call float @llvm.trunc.f32(float %x) |
| 106 | ret float %a |
| 107 | } |
| 108 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 109 | ; CHECK-LABEL: nearest32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 110 | ; CHECK: f32.nearest $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} |
| 111 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 112 | define float @nearest32(float %x) { |
Dan Gohman | 896e53f | 2015-08-24 18:23:13 +0000 | [diff] [blame] | 113 | %a = call float @llvm.nearbyint.f32(float %x) |
| 114 | ret float %a |
| 115 | } |
| 116 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 117 | ; CHECK-LABEL: nearest32_via_rint: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 118 | ; CHECK: f32.nearest $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} |
| 119 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 120 | define float @nearest32_via_rint(float %x) { |
Dan Gohman | 896e53f | 2015-08-24 18:23:13 +0000 | [diff] [blame] | 121 | %a = call float @llvm.rint.f32(float %x) |
| 122 | ret float %a |
| 123 | } |
Dan Gohman | b84ae9b | 2015-11-10 21:40:21 +0000 | [diff] [blame] | 124 | |
Dan Gohman | b84ae9b | 2015-11-10 21:40:21 +0000 | [diff] [blame] | 125 | ; CHECK-LABEL: fmin32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 126 | ; CHECK: f32.min $push1=, $pop{{[0-9]+}}, $pop[[LR]]{{$}} |
Dan Gohman | 4ba4816 | 2015-11-18 16:12:01 +0000 | [diff] [blame] | 127 | ; CHECK-NEXT: return $pop1{{$}} |
Dan Gohman | b84ae9b | 2015-11-10 21:40:21 +0000 | [diff] [blame] | 128 | define float @fmin32(float %x) { |
| 129 | %a = fcmp ult float %x, 0.0 |
| 130 | %b = select i1 %a, float %x, float 0.0 |
| 131 | ret float %b |
| 132 | } |
| 133 | |
| 134 | ; CHECK-LABEL: fmax32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 135 | ; CHECK: f32.max $push1=, $pop{{[0-9]+}}, $pop[[LR]]{{$}} |
Dan Gohman | 4ba4816 | 2015-11-18 16:12:01 +0000 | [diff] [blame] | 136 | ; CHECK-NEXT: return $pop1{{$}} |
Dan Gohman | b84ae9b | 2015-11-10 21:40:21 +0000 | [diff] [blame] | 137 | define float @fmax32(float %x) { |
| 138 | %a = fcmp ugt float %x, 0.0 |
| 139 | %b = select i1 %a, float %x, float 0.0 |
| 140 | ret float %b |
| 141 | } |
Dan Gohman | 9341c1d | 2015-12-10 04:52:33 +0000 | [diff] [blame] | 142 | |
Thomas Lively | 3afc346 | 2018-10-13 07:26:10 +0000 | [diff] [blame] | 143 | ; CHECK-LABEL: fmin32_intrinsic: |
| 144 | ; CHECK: f32.min $push0=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}} |
| 145 | ; CHECK-NEXT: return $pop0{{$}} |
| 146 | declare float @llvm.minimum.f32(float, float) |
| 147 | define float @fmin32_intrinsic(float %x, float %y) { |
| 148 | %a = call float @llvm.minimum.f32(float %x, float %y) |
| 149 | ret float %a |
| 150 | } |
| 151 | |
| 152 | ; CHECK-LABEL: fmax32_intrinsic: |
| 153 | ; CHECK: f32.max $push0=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}} |
| 154 | ; CHECK-NEXT: return $pop0{{$}} |
| 155 | declare float @llvm.maximum.f32(float, float) |
| 156 | define float @fmax32_intrinsic(float %x, float %y) { |
| 157 | %a = call float @llvm.maximum.f32(float %x, float %y) |
| 158 | ret float %a |
| 159 | } |
| 160 | |
Dan Gohman | 9341c1d | 2015-12-10 04:52:33 +0000 | [diff] [blame] | 161 | ; CHECK-LABEL: fma32: |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 162 | ; CHECK: {{^}} f32.call $push[[LR:[0-9]+]]=, fmaf@FUNCTION, $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}} |
| 163 | ; CHECK-NEXT: return $pop[[LR]]{{$}} |
Dan Gohman | 9341c1d | 2015-12-10 04:52:33 +0000 | [diff] [blame] | 164 | define float @fma32(float %a, float %b, float %c) { |
| 165 | %d = call float @llvm.fma.f32(float %a, float %b, float %c) |
| 166 | ret float %d |
| 167 | } |