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

Dan Gohman via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 15:25:51 PST 2015


Author: djg
Date: Wed Dec 16 17:25:51 2015
New Revision: 255847

URL: http://llvm.org/viewvc/llvm-project?rev=255847&view=rev
Log:
[WebAssembly] Fix legalization of shift operators on large integer types.

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

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp?rev=255847&r1=255846&r2=255847&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp Wed Dec 16 17:25:51 2015
@@ -207,6 +207,13 @@ MVT WebAssemblyTargetLowering::getScalar
   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");

Modified: llvm/trunk/test/CodeGen/WebAssembly/legalize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/legalize.ll?rev=255847&r1=255846&r2=255847&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/legalize.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/legalize.ll Wed Dec 16 17:25:51 2015
@@ -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
+}




More information about the llvm-commits mailing list