[llvm] r255181 - [WebAssembly] Fix legalization of shift operators with illegal types.

Dan Gohman via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 9 16:26:27 PST 2015


Author: djg
Date: Wed Dec  9 18:26:26 2015
New Revision: 255181

URL: http://llvm.org/viewvc/llvm-project?rev=255181&view=rev
Log:
[WebAssembly] Fix legalization of shift operators with illegal types.

Added:
    llvm/trunk/test/CodeGen/WebAssembly/legalize.ll
Modified:
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp?rev=255181&r1=255180&r2=255181&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp Wed Dec  9 18:26:26 2015
@@ -202,7 +202,13 @@ bool WebAssemblyTargetLowering::isOffset
 
 MVT WebAssemblyTargetLowering::getScalarShiftAmountTy(const DataLayout & /*DL*/,
                                                       EVT VT) const {
-  return VT.getSimpleVT();
+  unsigned BitWidth = NextPowerOf2(VT.getSizeInBits() - 1);
+  if (BitWidth > 1 && BitWidth < 8)
+    BitWidth = 8;
+  MVT Result = MVT::getIntegerVT(BitWidth);
+  assert(Result != MVT::INVALID_SIMPLE_VALUE_TYPE &&
+         "Unable to represent scalar shift amount type");
+  return Result;
 }
 
 const char *

Added: llvm/trunk/test/CodeGen/WebAssembly/legalize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/legalize.ll?rev=255181&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/legalize.ll (added)
+++ llvm/trunk/test/CodeGen/WebAssembly/legalize.ll Wed Dec  9 18:26:26 2015
@@ -0,0 +1,24 @@
+; RUN: llc < %s -asm-verbose=false | FileCheck %s
+
+; Test various types and operators that need to be legalized.
+
+target datalayout = "e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+; CHECK-LABEL: shl_i3:
+; CHECK: i32.const   $push0=, 7
+; CHECK: i32.and     $push1=, $1, $pop0
+; CHECK: i32.shl     $push2=, $0, $pop1
+define i3 @shl_i3(i3 %a, i3 %b, i3* %p) {
+  %t = shl i3 %a, %b
+  ret i3 %t
+}
+
+; CHECK-LABEL: shl_i53:
+; CHECK: i64.const   $push0=, 9007199254740991
+; CHECK: i64.and     $push1=, $1, $pop0
+; CHECK: i64.shl     $push2=, $0, $pop1
+define i53 @shl_i53(i53 %a, i53 %b, i53* %p) {
+  %t = shl i53 %a, %b
+  ret i53 %t
+}




More information about the llvm-commits mailing list