[llvm] r243860 - WebAssembly: implement getScalarShiftAmountTy so we can shift by amount, with type

JF Bastien jfb at google.com
Sun Aug 2 17:00:12 PDT 2015


Author: jfb
Date: Sun Aug  2 19:00:11 2015
New Revision: 243860

URL: http://llvm.org/viewvc/llvm-project?rev=243860&view=rev
Log:
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

Modified:
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.h
    llvm/trunk/test/CodeGen/WebAssembly/integer64.ll

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp?rev=243860&r1=243859&r2=243860&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp Sun Aug  2 19:00:11 2015
@@ -111,6 +111,11 @@ WebAssemblyTargetLowering::WebAssemblyTa
   // FIXME: setOperationAction...
 }
 
+MVT WebAssemblyTargetLowering::getScalarShiftAmountTy(const DataLayout &DL,
+                                                      EVT VT) const {
+  return VT.getSimpleVT();
+}
+
 //===----------------------------------------------------------------------===//
 // WebAssembly Lowering private implementation.
 //===----------------------------------------------------------------------===//

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.h?rev=243860&r1=243859&r2=243860&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.h (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.h Sun Aug  2 19:00:11 2015
@@ -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<ISD::OutputArg> &Outs,

Modified: llvm/trunk/test/CodeGen/WebAssembly/integer64.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/integer64.ll?rev=243860&r1=243859&r2=243860&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/integer64.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/integer64.ll Sun Aug  2 19:00:11 2015
@@ -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
-;}
+; 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
+}
 
-; 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
-;}
+; 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
+}
 
-; 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: 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))





More information about the llvm-commits mailing list