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