From a796bb8e0a72426c87912b85d6af8a164aa179e3 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 10 Dec 2015 00:26:26 +0000 Subject: [PATCH] [WebAssembly] Fix legalization of shift operators with illegal types. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255181 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../WebAssembly/WebAssemblyISelLowering.cpp | 8 ++++++- test/CodeGen/WebAssembly/legalize.ll | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/WebAssembly/legalize.ll diff --git a/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp index a8b93ca8a2f..37b82d6385a 100644 --- a/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp +++ b/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp @@ -202,7 +202,13 @@ bool WebAssemblyTargetLowering::isOffsetFoldingLegal( 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 * diff --git a/test/CodeGen/WebAssembly/legalize.ll b/test/CodeGen/WebAssembly/legalize.ll new file mode 100644 index 00000000000..4bfec212cf7 --- /dev/null +++ b/test/CodeGen/WebAssembly/legalize.ll @@ -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 +} -- 2.34.1