1; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt | FileCheck %s 2 3; Test that basic 64-bit floating-point operations assemble as expected. 4 5target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" 6target triple = "wasm32-unknown-unknown" 7 8declare double @llvm.fabs.f64(double) 9declare double @llvm.copysign.f64(double, double) 10declare double @llvm.sqrt.f64(double) 11declare double @llvm.ceil.f64(double) 12declare double @llvm.floor.f64(double) 13declare double @llvm.trunc.f64(double) 14declare double @llvm.nearbyint.f64(double) 15declare double @llvm.rint.f64(double) 16declare double @llvm.fma.f64(double, double, double) 17 18; CHECK-LABEL: fadd64: 19; CHECK-NEXT: .param f64, f64{{$}} 20; CHECK-NEXT: .result f64{{$}} 21; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}} 22; CHECK-NEXT: get_local $push[[L1:[0-9]+]]=, 1{{$}} 23; CHECK-NEXT: f64.add $push[[LR:[0-9]+]]=, $pop[[L0]], $pop[[L1]]{{$}} 24; CHECK-NEXT: return $pop[[LR]]{{$}} 25define double @fadd64(double %x, double %y) { 26 %a = fadd double %x, %y 27 ret double %a 28} 29 30; CHECK-LABEL: fsub64: 31; CHECK: f64.sub $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}} 32; CHECK-NEXT: return $pop[[LR]]{{$}} 33define double @fsub64(double %x, double %y) { 34 %a = fsub double %x, %y 35 ret double %a 36} 37 38; CHECK-LABEL: fmul64: 39; CHECK: f64.mul $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}} 40; CHECK-NEXT: return $pop[[LR]]{{$}} 41define double @fmul64(double %x, double %y) { 42 %a = fmul double %x, %y 43 ret double %a 44} 45 46; CHECK-LABEL: fdiv64: 47; CHECK: f64.div $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}} 48; CHECK-NEXT: return $pop[[LR]]{{$}} 49define double @fdiv64(double %x, double %y) { 50 %a = fdiv double %x, %y 51 ret double %a 52} 53 54; CHECK-LABEL: fabs64: 55; CHECK: f64.abs $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} 56; CHECK-NEXT: return $pop[[LR]]{{$}} 57define double @fabs64(double %x) { 58 %a = call double @llvm.fabs.f64(double %x) 59 ret double %a 60} 61 62; CHECK-LABEL: fneg64: 63; CHECK: f64.neg $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} 64; CHECK-NEXT: return $pop[[LR]]{{$}} 65define double @fneg64(double %x) { 66 %a = fsub double -0., %x 67 ret double %a 68} 69 70; CHECK-LABEL: copysign64: 71; CHECK: f64.copysign $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}} 72; CHECK-NEXT: return $pop[[LR]]{{$}} 73define double @copysign64(double %x, double %y) { 74 %a = call double @llvm.copysign.f64(double %x, double %y) 75 ret double %a 76} 77 78; CHECK-LABEL: sqrt64: 79; CHECK: f64.sqrt $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} 80; CHECK-NEXT: return $pop[[LR]]{{$}} 81define double @sqrt64(double %x) { 82 %a = call double @llvm.sqrt.f64(double %x) 83 ret double %a 84} 85 86; CHECK-LABEL: ceil64: 87; CHECK: f64.ceil $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} 88; CHECK-NEXT: return $pop[[LR]]{{$}} 89define double @ceil64(double %x) { 90 %a = call double @llvm.ceil.f64(double %x) 91 ret double %a 92} 93 94; CHECK-LABEL: floor64: 95; CHECK: f64.floor $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} 96; CHECK-NEXT: return $pop[[LR]]{{$}} 97define double @floor64(double %x) { 98 %a = call double @llvm.floor.f64(double %x) 99 ret double %a 100} 101 102; CHECK-LABEL: trunc64: 103; CHECK: f64.trunc $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} 104; CHECK-NEXT: return $pop[[LR]]{{$}} 105define double @trunc64(double %x) { 106 %a = call double @llvm.trunc.f64(double %x) 107 ret double %a 108} 109 110; CHECK-LABEL: nearest64: 111; CHECK: f64.nearest $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} 112; CHECK-NEXT: return $pop[[LR]]{{$}} 113define double @nearest64(double %x) { 114 %a = call double @llvm.nearbyint.f64(double %x) 115 ret double %a 116} 117 118; CHECK-LABEL: nearest64_via_rint: 119; CHECK: f64.nearest $push[[LR:[0-9]+]]=, $pop{{[0-9]+}}{{$}} 120; CHECK-NEXT: return $pop[[LR]]{{$}} 121define double @nearest64_via_rint(double %x) { 122 %a = call double @llvm.rint.f64(double %x) 123 ret double %a 124} 125 126; Min and max tests. LLVM currently only forms fminnan and fmaxnan nodes in 127; cases where there's a single fcmp with a select and it can prove that one 128; of the arms is never NaN, so we only test that case. In the future if LLVM 129; learns to form fminnan/fmaxnan in more cases, we can write more general 130; tests. 131 132; CHECK-LABEL: fmin64: 133; CHECK: f64.min $push1=, $pop{{[0-9]+}}, $pop[[LR]]{{$}} 134; CHECK-NEXT: return $pop1{{$}} 135define double @fmin64(double %x) { 136 %a = fcmp ult double %x, 0.0 137 %b = select i1 %a, double %x, double 0.0 138 ret double %b 139} 140 141; CHECK-LABEL: fmax64: 142; CHECK: f64.max $push1=, $pop{{[0-9]+}}, $pop[[LR]]{{$}} 143; CHECK-NEXT: return $pop1{{$}} 144define double @fmax64(double %x) { 145 %a = fcmp ugt double %x, 0.0 146 %b = select i1 %a, double %x, double 0.0 147 ret double %b 148} 149 150; CHECK-LABEL: fma64: 151; CHECK: {{^}} f64.call $push[[LR:[0-9]+]]=, fma@FUNCTION, $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}{{$}} 152; CHECK-NEXT: return $pop[[LR]]{{$}} 153define double @fma64(double %a, double %b, double %c) { 154 %d = call double @llvm.fma.f64(double %a, double %b, double %c) 155 ret double %d 156} 157