From 5bcfe245f9d9c0624685571fdbd398a5e1e5118a Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Mon, 3 Aug 2015 00:00:11 +0000 Subject: [PATCH] WebAssembly: implement getScalarShiftAmountTy so we can shift by amount, with type Summary: This currently sets the shift amount RHS to the same type as the LHS, and assumes that the LHS is a simple type. This isn't currently the case e.g. with weird integers sizes, but will eventually be true and will assert if not. That's what you get for having an experimental backend: break it and you get to keep both pieces. Most backends either set the RHS to MVT::i32 or MVT::i64, but WebAssembly is a virtual ISA and tries to have regular-looking binary operations where both operands are the same type (even if a 64-bit RHS shifter is slightly silly, hey it's free!). Subscribers: llvm-commits, sunfish, jfb Differential Revision: http://reviews.llvm.org/D11715 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243860 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../WebAssembly/WebAssemblyISelLowering.cpp | 5 ++ .../WebAssembly/WebAssemblyISelLowering.h | 2 + test/CodeGen/WebAssembly/integer64.ll | 62 +++++++++---------- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp index f8b4fbd3bde..4360116a7f1 100644 --- a/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp +++ b/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp @@ -111,6 +111,11 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering( // FIXME: setOperationAction... } +MVT WebAssemblyTargetLowering::getScalarShiftAmountTy(const DataLayout &DL, + EVT VT) const { + return VT.getSimpleVT(); +} + //===----------------------------------------------------------------------===// // WebAssembly Lowering private implementation. //===----------------------------------------------------------------------===// diff --git a/lib/Target/WebAssembly/WebAssemblyISelLowering.h b/lib/Target/WebAssembly/WebAssemblyISelLowering.h index 3e8252604d6..12b4fe62864 100644 --- a/lib/Target/WebAssembly/WebAssemblyISelLowering.h +++ b/lib/Target/WebAssembly/WebAssemblyISelLowering.h @@ -45,6 +45,8 @@ private: /// right decision when generating code for different targets. const WebAssemblySubtarget *Subtarget; + MVT getScalarShiftAmountTy(const DataLayout &DL, EVT) const override; + bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg, const SmallVectorImpl &Outs, diff --git a/test/CodeGen/WebAssembly/integer64.ll b/test/CodeGen/WebAssembly/integer64.ll index 4ac2846754c..540646cc388 100644 --- a/test/CodeGen/WebAssembly/integer64.ll +++ b/test/CodeGen/WebAssembly/integer64.ll @@ -109,39 +109,35 @@ define i64 @xor64(i64 %x, i64 %y) { ret i64 %a } -; FIXME: 64-bit shifts have an extra truncate of the input shift value, which -; WebAssembly hasn't taught isel to match yet. Fix with -; getScalarShiftAmountTy. - -; C;HECK-LABEL: shl64: -; C;HECK-NEXT: (setlocal @0 (argument 1)) -; C;HECK-NEXT: (setlocal @1 (argument 0)) -; C;HECK-NEXT: (setlocal @2 (SHL_I64 @1 @0)) -; C;HECK-NEXT: (return @2) -;define i64 @shl64(i64 %x, i64 %y) { -; %a = shl i64 %x, %y -; ret i64 %a -;} - -; C;HECK-LABEL: shr64: -; C;HECK-NEXT: (setlocal @0 (argument 1)) -; C;HECK-NEXT: (setlocal @1 (argument 0)) -; C;HECK-NEXT: (setlocal @2 (SHR_I64 @1 @0)) -; C;HECK-NEXT: (return @2) -;define i64 @shr64(i64 %x, i64 %y) { -; %a = lshr i64 %x, %y -; ret i64 %a -;} - -; C;HECK-LABEL: sar64: -; C;HECK-NEXT: (setlocal @0 (argument 1)) -; C;HECK-NEXT: (setlocal @1 (argument 0)) -; C;HECK-NEXT: (setlocal @2 (SAR_I64 @1 @0)) -; C;HECK-NEXT: (return @2) -;define i64 @sar64(i64 %x, i64 %y) { -; %a = ashr i64 %x, %y -; ret i64 %a -;} +; CHECK-LABEL: shl64: +; CHECK-NEXT: (setlocal @0 (argument 1)) +; CHECK-NEXT: (setlocal @1 (argument 0)) +; CHECK-NEXT: (setlocal @2 (SHL_I64 @1 @0)) +; CHECK-NEXT: (return @2) +define i64 @shl64(i64 %x, i64 %y) { + %a = shl i64 %x, %y + ret i64 %a +} + +; CHECK-LABEL: shr64: +; CHECK-NEXT: (setlocal @0 (argument 1)) +; CHECK-NEXT: (setlocal @1 (argument 0)) +; CHECK-NEXT: (setlocal @2 (SHR_I64 @1 @0)) +; CHECK-NEXT: (return @2) +define i64 @shr64(i64 %x, i64 %y) { + %a = lshr i64 %x, %y + ret i64 %a +} + +; CHECK-LABEL: sar64: +; CHECK-NEXT: (setlocal @0 (argument 1)) +; CHECK-NEXT: (setlocal @1 (argument 0)) +; CHECK-NEXT: (setlocal @2 (SAR_I64 @1 @0)) +; CHECK-NEXT: (return @2) +define i64 @sar64(i64 %x, i64 %y) { + %a = ashr i64 %x, %y + ret i64 %a +} ; CHECK-LABEL: clz64: ; CHECK-NEXT: (setlocal @0 (argument 0)) -- 2.34.1