From: Dan Gohman <dan433584@gmail.com>
Date: Wed, 16 Dec 2015 23:25:51 +0000 (+0000)
Subject: [WebAssembly] Fix legalization of shift operators on large integer types.
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f2640be5dfc41d11ca28ad60ab5e45bf4db7e36e;p=oota-llvm.git

[WebAssembly] Fix legalization of shift operators on large integer types.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255847 91177308-0d34-0410-b5e6-96231b3b80d8
---

diff --git a/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index 2364366f3f5..ed7cb1909d9 100644
--- a/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -207,6 +207,13 @@ MVT WebAssemblyTargetLowering::getScalarShiftAmountTy(const DataLayout & /*DL*/,
   unsigned BitWidth = NextPowerOf2(VT.getSizeInBits() - 1);
   if (BitWidth > 1 && BitWidth < 8)
     BitWidth = 8;
+
+  if (BitWidth > 64) {
+    BitWidth = 64;
+    assert(BitWidth >= Log2_32_Ceil(VT.getSizeInBits()) &&
+           "64-bit shift counts ought to be enough for anyone");
+  }
+
   MVT Result = MVT::getIntegerVT(BitWidth);
   assert(Result != MVT::INVALID_SIMPLE_VALUE_TYPE &&
          "Unable to represent scalar shift amount type");
diff --git a/test/CodeGen/WebAssembly/legalize.ll b/test/CodeGen/WebAssembly/legalize.ll
index 7cc1246a86e..e780b2ee36c 100644
--- a/test/CodeGen/WebAssembly/legalize.ll
+++ b/test/CodeGen/WebAssembly/legalize.ll
@@ -51,3 +51,12 @@ define float @fpconv_f64_f32(double *%p) {
   %e = fptrunc double %v to float
   ret float %e
 }
+
+; Check that big shifts work. This generates a big pile of code from the
+; legalizer; the main thing here is that we don't abort.
+
+; CHECK-LABEL: bigshift:
+define i1024 @bigshift(i1024 %a, i1024 %b) {
+    %c = shl i1024 %a, %b
+    ret i1024 %c
+}