From 270e6f8a27d535d22ab84b05936889430b0f0be6 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 15 Sep 2015 00:55:19 +0000 Subject: [PATCH] [WebAssembly] Implement int64-to-int32 conversion. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247649 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/WebAssembly/WebAssemblyInstrConv.td | 3 +++ test/CodeGen/WebAssembly/conv.ll | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/CodeGen/WebAssembly/conv.ll diff --git a/lib/Target/WebAssembly/WebAssemblyInstrConv.td b/lib/Target/WebAssembly/WebAssemblyInstrConv.td index 3fa29061b1d..6479a67167b 100644 --- a/lib/Target/WebAssembly/WebAssemblyInstrConv.td +++ b/lib/Target/WebAssembly/WebAssemblyInstrConv.td @@ -42,3 +42,6 @@ * float64.cvt_unsigned[int64]: convert an unsigned 64-bit integer to a 64-bit float * float64.reinterpret[int64]: reinterpret the bits of a 64-bit integer as a 64-bit float */ + +def WRAP_I64_I32 : I<(outs Int32:$dst), (ins Int64:$src), + [(set Int32:$dst, (trunc Int64:$src))]>; diff --git a/test/CodeGen/WebAssembly/conv.ll b/test/CodeGen/WebAssembly/conv.ll new file mode 100644 index 00000000000..ae82abfe79d --- /dev/null +++ b/test/CodeGen/WebAssembly/conv.ll @@ -0,0 +1,16 @@ +; RUN: llc < %s -asm-verbose=false | FileCheck %s + +; Test that basic conversion operations assemble as expected. + +target datalayout = "e-p:32:32-i64:64-n32:64-S128" +target triple = "wasm32-unknown-unknown" + +; CHECK-LABEL: $wrap_i64_i32 +; CHECK-NEXT: (param i64) (result i32) +; CHECK-NEXT: (setlocal @0 (argument 0)) +; CHECK-NEXT: (setlocal @1 (wrap_i64 @0)) +; CHECK-NEXT: (return @1) +define i32 @wrap_i64_i32(i64 %x) { + %a = trunc i64 %x to i32 + ret i32 %a +} -- 2.34.1