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 32-bit floating-point comparison operations assemble as
      4 ; expected.
      5 
      6 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
      7 target triple = "wasm32-unknown-unknown"
      8 
      9 ; CHECK-LABEL: ord_f32:
     10 ; CHECK-NEXT: .param f32, f32{{$}}
     11 ; CHECK-NEXT: .result i32{{$}}
     12 ; CHECK-NEXT: f32.eq $push[[NUM0:[0-9]+]]=, $0, $0{{$}}
     13 ; CHECK-NEXT: f32.eq $push[[NUM1:[0-9]+]]=, $1, $1{{$}}
     14 ; CHECK-NEXT: i32.and $push[[NUM2:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM1]]{{$}}
     15 ; CHECK-NEXT: return $pop[[NUM2]]{{$}}
     16 define i32 @ord_f32(float %x, float %y) {
     17   %a = fcmp ord float %x, %y
     18   %b = zext i1 %a to i32
     19   ret i32 %b
     20 }
     21 
     22 ; CHECK-LABEL: uno_f32:
     23 ; CHECK-NEXT: .param f32, f32{{$}}
     24 ; CHECK-NEXT: .result i32{{$}}
     25 ; CHECK-NEXT: f32.ne $push[[NUM0:[0-9]+]]=, $0, $0{{$}}
     26 ; CHECK-NEXT: f32.ne $push[[NUM1:[0-9]+]]=, $1, $1{{$}}
     27 ; CHECK-NEXT: i32.or $push[[NUM2:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM1]]{{$}}
     28 ; CHECK-NEXT: return $pop[[NUM2]]{{$}}
     29 define i32 @uno_f32(float %x, float %y) {
     30   %a = fcmp uno float %x, %y
     31   %b = zext i1 %a to i32
     32   ret i32 %b
     33 }
     34 
     35 ; CHECK-LABEL: oeq_f32:
     36 ; CHECK-NEXT: .param f32, f32{{$}}
     37 ; CHECK-NEXT: .result i32{{$}}
     38 ; CHECK-NEXT: f32.eq $push[[NUM:[0-9]+]]=, $0, $1{{$}}
     39 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
     40 define i32 @oeq_f32(float %x, float %y) {
     41   %a = fcmp oeq float %x, %y
     42   %b = zext i1 %a to i32
     43   ret i32 %b
     44 }
     45 
     46 ; CHECK-LABEL: une_f32:
     47 ; CHECK: f32.ne $push[[NUM:[0-9]+]]=, $0, $1{{$}}
     48 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
     49 define i32 @une_f32(float %x, float %y) {
     50   %a = fcmp une float %x, %y
     51   %b = zext i1 %a to i32
     52   ret i32 %b
     53 }
     54 
     55 ; CHECK-LABEL: olt_f32:
     56 ; CHECK: f32.lt $push[[NUM:[0-9]+]]=, $0, $1{{$}}
     57 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
     58 define i32 @olt_f32(float %x, float %y) {
     59   %a = fcmp olt float %x, %y
     60   %b = zext i1 %a to i32
     61   ret i32 %b
     62 }
     63 
     64 ; CHECK-LABEL: ole_f32:
     65 ; CHECK: f32.le $push[[NUM:[0-9]+]]=, $0, $1{{$}}
     66 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
     67 define i32 @ole_f32(float %x, float %y) {
     68   %a = fcmp ole float %x, %y
     69   %b = zext i1 %a to i32
     70   ret i32 %b
     71 }
     72 
     73 ; CHECK-LABEL: ogt_f32:
     74 ; CHECK: f32.gt $push[[NUM:[0-9]+]]=, $0, $1{{$}}
     75 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
     76 define i32 @ogt_f32(float %x, float %y) {
     77   %a = fcmp ogt float %x, %y
     78   %b = zext i1 %a to i32
     79   ret i32 %b
     80 }
     81 
     82 ; CHECK-LABEL: oge_f32:
     83 ; CHECK: f32.ge $push[[NUM:[0-9]+]]=, $0, $1{{$}}
     84 ; CHECK-NEXT: return $pop[[NUM]]{{$}}
     85 define i32 @oge_f32(float %x, float %y) {
     86   %a = fcmp oge float %x, %y
     87   %b = zext i1 %a to i32
     88   ret i32 %b
     89 }
     90 
     91 ; Expanded comparisons, which also check for NaN.
     92 
     93 ; CHECK-LABEL: ueq_f32:
     94 ; CHECK-NEXT: .param f32, f32{{$}}
     95 ; CHECK-NEXT: .result i32{{$}}
     96 ; CHECK-NEXT: f32.eq $push[[NUM0:[0-9]+]]=, $0, $1{{$}}
     97 ; CHECK-NEXT: f32.ne $push[[NUM1:[0-9]+]]=, $0, $0{{$}}
     98 ; CHECK-NEXT: f32.ne $push[[NUM2:[0-9]+]]=, $1, $1{{$}}
     99 ; CHECK-NEXT: i32.or $push[[NUM3:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM2]]{{$}}
    100 ; CHECK-NEXT: i32.or $push[[NUM4:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM3]]{{$}}
    101 ; CHECK-NEXT: return $pop[[NUM4]]{{$}}
    102 define i32 @ueq_f32(float %x, float %y) {
    103   %a = fcmp ueq float %x, %y
    104   %b = zext i1 %a to i32
    105   ret i32 %b
    106 }
    107 
    108 ; CHECK-LABEL: one_f32:
    109 ; CHECK-NEXT: .param f32, f32{{$}}
    110 ; CHECK-NEXT: .result i32{{$}}
    111 ; CHECK-NEXT: f32.ne $push[[NUM0:[0-9]+]]=, $0, $1{{$}}
    112 ; CHECK-NEXT: f32.eq $push[[NUM1:[0-9]+]]=, $0, $0{{$}}
    113 ; CHECK-NEXT: f32.eq $push[[NUM2:[0-9]+]]=, $1, $1{{$}}
    114 ; CHECK-NEXT: i32.and $push[[NUM3:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM2]]{{$}}
    115 ; CHECK-NEXT: i32.and $push[[NUM4:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM3]]{{$}}
    116 ; CHECK-NEXT: return $pop[[NUM4]]
    117 define i32 @one_f32(float %x, float %y) {
    118   %a = fcmp one float %x, %y
    119   %b = zext i1 %a to i32
    120   ret i32 %b
    121 }
    122 
    123 ; CHECK-LABEL: ult_f32:
    124 ; CHECK-NEXT: .param f32, f32{{$}}
    125 ; CHECK-NEXT: .result i32{{$}}
    126 ; CHECK-NEXT: f32.lt $push[[NUM0:[0-9]+]]=, $0, $1{{$}}
    127 ; CHECK-NEXT: f32.ne $push[[NUM1:[0-9]+]]=, $0, $0{{$}}
    128 ; CHECK-NEXT: f32.ne $push[[NUM2:[0-9]+]]=, $1, $1{{$}}
    129 ; CHECK-NEXT: i32.or $push[[NUM3:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM2]]{{$}}
    130 ; CHECK-NEXT: i32.or $push[[NUM4:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM3]]{{$}}
    131 ; CHECK-NEXT: return $pop[[NUM4]]{{$}}
    132 define i32 @ult_f32(float %x, float %y) {
    133   %a = fcmp ult float %x, %y
    134   %b = zext i1 %a to i32
    135   ret i32 %b
    136 }
    137 
    138 ; CHECK-LABEL: ule_f32:
    139 ; CHECK-NEXT: .param f32, f32{{$}}
    140 ; CHECK-NEXT: .result i32{{$}}
    141 ; CHECK-NEXT: f32.le $push[[NUM0:[0-9]+]]=, $0, $1{{$}}
    142 ; CHECK-NEXT: f32.ne $push[[NUM1:[0-9]+]]=, $0, $0{{$}}
    143 ; CHECK-NEXT: f32.ne $push[[NUM2:[0-9]+]]=, $1, $1{{$}}
    144 ; CHECK-NEXT: i32.or $push[[NUM3:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM2]]{{$}}
    145 ; CHECK-NEXT: i32.or $push[[NUM4:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM3]]{{$}}
    146 ; CHECK-NEXT: return $pop[[NUM4]]{{$}}
    147 define i32 @ule_f32(float %x, float %y) {
    148   %a = fcmp ule float %x, %y
    149   %b = zext i1 %a to i32
    150   ret i32 %b
    151 }
    152 
    153 ; CHECK-LABEL: ugt_f32:
    154 ; CHECK-NEXT: .param f32, f32{{$}}
    155 ; CHECK-NEXT: .result i32{{$}}
    156 ; CHECK-NEXT: f32.gt $push[[NUM0:[0-9]+]]=, $0, $1{{$}}
    157 ; CHECK-NEXT: f32.ne $push[[NUM1:[0-9]+]]=, $0, $0{{$}}
    158 ; CHECK-NEXT: f32.ne $push[[NUM2:[0-9]+]]=, $1, $1{{$}}
    159 ; CHECK-NEXT: i32.or $push[[NUM3:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM2]]{{$}}
    160 ; CHECK-NEXT: i32.or $push[[NUM4:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM3]]{{$}}
    161 ; CHECK-NEXT: return $pop[[NUM4]]{{$}}
    162 define i32 @ugt_f32(float %x, float %y) {
    163   %a = fcmp ugt float %x, %y
    164   %b = zext i1 %a to i32
    165   ret i32 %b
    166 }
    167 
    168 ; CHECK-LABEL: uge_f32:
    169 ; CHECK-NEXT: .param f32, f32{{$}}
    170 ; CHECK-NEXT: .result i32{{$}}
    171 ; CHECK-NEXT: f32.ge $push[[NUM0:[0-9]+]]=, $0, $1{{$}}
    172 ; CHECK-NEXT: f32.ne $push[[NUM1:[0-9]+]]=, $0, $0{{$}}
    173 ; CHECK-NEXT: f32.ne $push[[NUM2:[0-9]+]]=, $1, $1{{$}}
    174 ; CHECK-NEXT: i32.or $push[[NUM3:[0-9]+]]=, $pop[[NUM1]], $pop[[NUM2]]{{$}}
    175 ; CHECK-NEXT: i32.or $push[[NUM4:[0-9]+]]=, $pop[[NUM0]], $pop[[NUM3]]{{$}}
    176 ; CHECK-NEXT: return $pop[[NUM4]]{{$}}
    177 define i32 @uge_f32(float %x, float %y) {
    178   %a = fcmp uge float %x, %y
    179   %b = zext i1 %a to i32
    180   ret i32 %b
    181 }
    182