[WebAssembly] Fix legalization of shift operators with illegal types.
[oota-llvm.git] / lib / Target / WebAssembly / WebAssemblyISelLowering.cpp
index a8b93ca8a2fb963428b068863edf2adf630403ce..37b82d6385a1557d8764409dc2daa4adf5f2c446 100644 (file)
@@ -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 *