[llvm] r249225 - [WebAssembly] Implement the remaining conversion operations.

Dan Gohman via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 19:10:29 PDT 2015


Author: djg
Date: Fri Oct  2 21:10:28 2015
New Revision: 249225

URL: http://llvm.org/viewvc/llvm-project?rev=249225&view=rev
Log:
[WebAssembly] Implement the remaining conversion operations.

This is a temporary assembly syntax that will likely evolve along with
broader upcoming syntax changes.

Modified:
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrConv.td
    llvm/trunk/test/CodeGen/WebAssembly/conv.ll

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrConv.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrConv.td?rev=249225&r1=249224&r2=249225&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrConv.td (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrConv.td Fri Oct  2 21:10:28 2015
@@ -13,35 +13,58 @@
 ///
 //===----------------------------------------------------------------------===//
 
-/*
- * TODO(jfb): Add the following.
- *
- * i32.wrap[i64]: wrap a 64-bit integer to a 32-bit integer
- * i32.trunc_s[f32]: truncate a 32-bit float to a signed 32-bit integer
- * i32.trunc_s[f64]: truncate a 64-bit float to a signed 32-bit integer
- * i32.trunc_u[f32]: truncate a 32-bit float to an unsigned 32-bit integer
- * i32.trunc_u[f64]: truncate a 64-bit float to an unsigned 32-bit integer
- * i32.reinterpret[f32]: reinterpret the bits of a 32-bit float as a 32-bit integer
- * i64.extend_s[i32]: extend a signed 32-bit integer to a 64-bit integer
- * i64.extend_u[i32]: extend an unsigned 32-bit integer to a 64-bit integer
- * i64.trunc_s[f32]: truncate a 32-bit float to a signed 64-bit integer
- * i64.trunc_s[f64]: truncate a 64-bit float to a signed 64-bit integer
- * i64.trunc_u[f32]: truncate a 32-bit float to an unsigned 64-bit integer
- * i64.trunc_u[f64]: truncate a 64-bit float to an unsigned 64-bit integer
- * i64.reinterpret[f64]: reinterpret the bits of a 64-bit float as a 64-bit integer
- * f32.demote[f64]: demote a 64-bit float to a 32-bit float
- * f32.convert_s[i32]: convert a signed 32-bit integer to a 32-bit float
- * f32.convert_s[i64]: convert a signed 64-bit integer to a 32-bit float
- * f32.convert_u[i32]: convert an unsigned 32-bit integer to a 32-bit float
- * f32.convert_u[i64]: convert an unsigned 64-bit integer to a 32-bit float
- * f32.reinterpret[i32]: reinterpret the bits of a 32-bit integer as a 32-bit float
- * f64.promote[f32]: promote a 32-bit float to a 64-bit float
- * f64.convert_s[i32]: convert a signed 32-bit integer to a 64-bit float
- * f64.convert_s[i64]: convert a signed 64-bit integer to a 64-bit float
- * f64.convert_u[i32]: convert an unsigned 32-bit integer to a 64-bit float
- * f64.convert_u[i64]: convert an unsigned 64-bit integer to a 64-bit float
- * f64.reinterpret[i64]: reinterpret the bits of a 64-bit integer as a 64-bit float
- */
-
-def WRAP_I64_I32 : I<(outs I32:$dst), (ins I64:$src),
+def I32_WRAP_I64 : I<(outs I32:$dst), (ins I64:$src),
                      [(set I32:$dst, (trunc I64:$src))]>;
+
+def I64_EXTEND_S_I32 : I<(outs I64:$dst), (ins I32:$src),
+                         [(set I64:$dst, (sext I32:$src))]>;
+def I64_EXTEND_U_I32 : I<(outs I64:$dst), (ins I32:$src),
+                         [(set I64:$dst, (zext I32:$src))]>;
+
+def I32_TRUNC_S_F32 : I<(outs I32:$dst), (ins F32:$src),
+                        [(set I32:$dst, (fp_to_sint F32:$src))]>;
+def I32_TRUNC_U_F32 : I<(outs I32:$dst), (ins F32:$src),
+                        [(set I32:$dst, (fp_to_uint F32:$src))]>;
+def I64_TRUNC_S_F32 : I<(outs I64:$dst), (ins F32:$src),
+                        [(set I64:$dst, (fp_to_sint F32:$src))]>;
+def I64_TRUNC_U_F32 : I<(outs I64:$dst), (ins F32:$src),
+                        [(set I64:$dst, (fp_to_uint F32:$src))]>;
+def I32_TRUNC_S_F64 : I<(outs I32:$dst), (ins F64:$src),
+                        [(set I32:$dst, (fp_to_sint F64:$src))]>;
+def I32_TRUNC_U_F64 : I<(outs I32:$dst), (ins F64:$src),
+                        [(set I32:$dst, (fp_to_uint F64:$src))]>;
+def I64_TRUNC_S_F64 : I<(outs I64:$dst), (ins F64:$src),
+                        [(set I64:$dst, (fp_to_sint F64:$src))]>;
+def I64_TRUNC_U_F64 : I<(outs I64:$dst), (ins F64:$src),
+                        [(set I64:$dst, (fp_to_uint F64:$src))]>;
+
+def F32_CONVERT_S_I32 : I<(outs F32:$dst), (ins I32:$src),
+                          [(set F32:$dst, (sint_to_fp I32:$src))]>;
+def F32_CONVERT_U_I32 : I<(outs F32:$dst), (ins I32:$src),
+                          [(set F32:$dst, (uint_to_fp I32:$src))]>;
+def F64_CONVERT_S_I32 : I<(outs F64:$dst), (ins I32:$src),
+                          [(set F64:$dst, (sint_to_fp I32:$src))]>;
+def F64_CONVERT_U_I32 : I<(outs F64:$dst), (ins I32:$src),
+                          [(set F64:$dst, (uint_to_fp I32:$src))]>;
+def F32_CONVERT_S_I64 : I<(outs F32:$dst), (ins I64:$src),
+                          [(set F32:$dst, (sint_to_fp I64:$src))]>;
+def F32_CONVERT_U_I64 : I<(outs F32:$dst), (ins I64:$src),
+                          [(set F32:$dst, (uint_to_fp I64:$src))]>;
+def F64_CONVERT_S_I64 : I<(outs F64:$dst), (ins I64:$src),
+                          [(set F64:$dst, (sint_to_fp I64:$src))]>;
+def F64_CONVERT_U_I64 : I<(outs F64:$dst), (ins I64:$src),
+                          [(set F64:$dst, (uint_to_fp I64:$src))]>;
+
+def F64_PROMOTE_F32 : I<(outs F64:$dst), (ins F32:$src),
+                        [(set F64:$dst, (fextend F32:$src))]>;
+def F32_DEMOTE_F64 : I<(outs F32:$dst), (ins F64:$src),
+                       [(set F32:$dst, (fround F64:$src))]>;
+
+def I32_REINTERPRET_F32 : I<(outs I32:$dst), (ins F32:$src),
+                            [(set I32:$dst, (bitconvert F32:$src))]>;
+def F32_REINTERPRET_I32 : I<(outs F32:$dst), (ins I32:$src),
+                            [(set F32:$dst, (bitconvert I32:$src))]>;
+def I64_REINTERPRET_F64 : I<(outs I64:$dst), (ins F64:$src),
+                            [(set I64:$dst, (bitconvert F64:$src))]>;
+def F64_REINTERPRET_I64 : I<(outs F64:$dst), (ins I64:$src),
+                            [(set F64:$dst, (bitconvert I64:$src))]>;

Modified: llvm/trunk/test/CodeGen/WebAssembly/conv.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/conv.ll?rev=249225&r1=249224&r2=249225&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/conv.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/conv.ll Fri Oct  2 21:10:28 2015
@@ -5,12 +5,212 @@
 target datalayout = "e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"
 
-; CHECK-LABEL: $wrap_i64_i32
+; CHECK-LABEL: $i32_wrap_i64
 ; CHECK-NEXT: (param i64) (result i32)
 ; CHECK-NEXT: (set_local @0 (argument 0))
-; CHECK-NEXT: (set_local @1 (wrap_i64 @0))
+; CHECK-NEXT: (set_local @1 (i32_wrap @0))
 ; CHECK-NEXT: (return @1)
-define i32 @wrap_i64_i32(i64 %x) {
+define i32 @i32_wrap_i64(i64 %x) {
   %a = trunc i64 %x to i32
   ret i32 %a
 }
+
+; CHECK-LABEL: $i64_extend_s_i32
+; CHECK-NEXT: (param i32) (result i64)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (i64_extend_s @0))
+; CHECK-NEXT: (return @1)
+define i64 @i64_extend_s_i32(i32 %x) {
+  %a = sext i32 %x to i64
+  ret i64 %a
+}
+
+; CHECK-LABEL: $i64_extend_u_i32
+; CHECK-NEXT: (param i32) (result i64)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (i64_extend_u @0))
+; CHECK-NEXT: (return @1)
+define i64 @i64_extend_u_i32(i32 %x) {
+  %a = zext i32 %x to i64
+  ret i64 %a
+}
+
+; CHECK-LABEL: $i32_trunc_s_f32
+; CHECK-NEXT: (param f32) (result i32)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (i32_trunc_s @0))
+; CHECK-NEXT: (return @1)
+define i32 @i32_trunc_s_f32(float %x) {
+  %a = fptosi float %x to i32
+  ret i32 %a
+}
+
+; CHECK-LABEL: $i32_trunc_u_f32
+; CHECK-NEXT: (param f32) (result i32)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (i32_trunc_u @0))
+; CHECK-NEXT: (return @1)
+define i32 @i32_trunc_u_f32(float %x) {
+  %a = fptoui float %x to i32
+  ret i32 %a
+}
+
+; CHECK-LABEL: $i32_trunc_s_f64
+; CHECK-NEXT: (param f64) (result i32)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (i32_trunc_s @0))
+; CHECK-NEXT: (return @1)
+define i32 @i32_trunc_s_f64(double %x) {
+  %a = fptosi double %x to i32
+  ret i32 %a
+}
+
+; CHECK-LABEL: $i32_trunc_u_f64
+; CHECK-NEXT: (param f64) (result i32)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (i32_trunc_u @0))
+; CHECK-NEXT: (return @1)
+define i32 @i32_trunc_u_f64(double %x) {
+  %a = fptoui double %x to i32
+  ret i32 %a
+}
+
+; CHECK-LABEL: $i64_trunc_s_f32
+; CHECK-NEXT: (param f32) (result i64)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (i64_trunc_s @0))
+; CHECK-NEXT: (return @1)
+define i64 @i64_trunc_s_f32(float %x) {
+  %a = fptosi float %x to i64
+  ret i64 %a
+}
+
+; CHECK-LABEL: $i64_trunc_u_f32
+; CHECK-NEXT: (param f32) (result i64)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (i64_trunc_u @0))
+; CHECK-NEXT: (return @1)
+define i64 @i64_trunc_u_f32(float %x) {
+  %a = fptoui float %x to i64
+  ret i64 %a
+}
+
+; CHECK-LABEL: $i64_trunc_s_f64
+; CHECK-NEXT: (param f64) (result i64)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (i64_trunc_s @0))
+; CHECK-NEXT: (return @1)
+define i64 @i64_trunc_s_f64(double %x) {
+  %a = fptosi double %x to i64
+  ret i64 %a
+}
+
+; CHECK-LABEL: $i64_trunc_u_f64
+; CHECK-NEXT: (param f64) (result i64)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (i64_trunc_u @0))
+; CHECK-NEXT: (return @1)
+define i64 @i64_trunc_u_f64(double %x) {
+  %a = fptoui double %x to i64
+  ret i64 %a
+}
+
+; CHECK-LABEL: $f32_convert_s_i32
+; CHECK-NEXT: (param i32) (result f32)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (f32_convert_s @0))
+; CHECK-NEXT: (return @1)
+define float @f32_convert_s_i32(i32 %x) {
+  %a = sitofp i32 %x to float
+  ret float %a
+}
+
+; CHECK-LABEL: $f32_convert_u_i32
+; CHECK-NEXT: (param i32) (result f32)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (f32_convert_u @0))
+; CHECK-NEXT: (return @1)
+define float @f32_convert_u_i32(i32 %x) {
+  %a = uitofp i32 %x to float
+  ret float %a
+}
+
+; CHECK-LABEL: $f64_convert_s_i32
+; CHECK-NEXT: (param i32) (result f64)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (f64_convert_s @0))
+; CHECK-NEXT: (return @1)
+define double @f64_convert_s_i32(i32 %x) {
+  %a = sitofp i32 %x to double
+  ret double %a
+}
+
+; CHECK-LABEL: $f64_convert_u_i32
+; CHECK-NEXT: (param i32) (result f64)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (f64_convert_u @0))
+; CHECK-NEXT: (return @1)
+define double @f64_convert_u_i32(i32 %x) {
+  %a = uitofp i32 %x to double
+  ret double %a
+}
+
+; CHECK-LABEL: $f32_convert_s_i64
+; CHECK-NEXT: (param i64) (result f32)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (f32_convert_s @0))
+; CHECK-NEXT: (return @1)
+define float @f32_convert_s_i64(i64 %x) {
+  %a = sitofp i64 %x to float
+  ret float %a
+}
+
+; CHECK-LABEL: $f32_convert_u_i64
+; CHECK-NEXT: (param i64) (result f32)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (f32_convert_u @0))
+; CHECK-NEXT: (return @1)
+define float @f32_convert_u_i64(i64 %x) {
+  %a = uitofp i64 %x to float
+  ret float %a
+}
+
+; CHECK-LABEL: $f64_convert_s_i64
+; CHECK-NEXT: (param i64) (result f64)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (f64_convert_s @0))
+; CHECK-NEXT: (return @1)
+define double @f64_convert_s_i64(i64 %x) {
+  %a = sitofp i64 %x to double
+  ret double %a
+}
+
+; CHECK-LABEL: $f64_convert_u_i64
+; CHECK-NEXT: (param i64) (result f64)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (f64_convert_u @0))
+; CHECK-NEXT: (return @1)
+define double @f64_convert_u_i64(i64 %x) {
+  %a = uitofp i64 %x to double
+  ret double %a
+}
+
+; CHECK-LABEL: $f64_promote_f32
+; CHECK-NEXT: (param f32) (result f64)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (f64_promote @0))
+; CHECK-NEXT: (return @1)
+define double @f64_promote_f32(float %x) {
+  %a = fpext float %x to double
+  ret double %a
+}
+
+; CHECK-LABEL: $f32_demote_f64
+; CHECK-NEXT: (param f64) (result f32)
+; CHECK-NEXT: (set_local @0 (argument 0))
+; CHECK-NEXT: (set_local @1 (f32_demote @0))
+; CHECK-NEXT: (return @1)
+define float @f32_demote_f64(double %x) {
+  %a = fptrunc double %x to float
+  ret float %a
+}




More information about the llvm-commits mailing list