[WebAssembly] Teach fast-isel to gracefully recover from illegal return types.
authorDan Gohman <dan433584@gmail.com>
Tue, 17 Apr 2018 20:46:42 +0000 (20:46 +0000)
committerDan Gohman <dan433584@gmail.com>
Tue, 17 Apr 2018 20:46:42 +0000 (20:46 +0000)
Fixes PR36564.

llvm-svn: 330215

llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
llvm/test/CodeGen/WebAssembly/fast-isel-i24.ll [new file with mode: 0644]

index f3ee6e7..c13dd7a 100644 (file)
@@ -703,8 +703,12 @@ bool WebAssemblyFastISel::fastLowerArguments() {
   for (auto const &Arg : F->args())
     MFI->addParam(getLegalType(getSimpleType(Arg.getType())));
 
-  if (!F->getReturnType()->isVoidTy())
-    MFI->addResult(getLegalType(getSimpleType(F->getReturnType())));
+  if (!F->getReturnType()->isVoidTy()) {
+    MVT::SimpleValueType RetTy = getSimpleType(F->getReturnType());
+    if (RetTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
+      return false;
+    MFI->addResult(getLegalType(RetTy));
+  }
 
   return true;
 }
diff --git a/llvm/test/CodeGen/WebAssembly/fast-isel-i24.ll b/llvm/test/CodeGen/WebAssembly/fast-isel-i24.ll
new file mode 100644 (file)
index 0000000..d3823f9
--- /dev/null
@@ -0,0 +1,16 @@
+; RUN: llc < %s -O0
+; PR36564
+
+; Test that fast-isel properly copes with i24 arguments and return types.
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown-wasm"
+
+define i24 @add(i24 %x, i24 %y) {
+    %z = add i24 %x, %y
+    ret i24 %z
+}
+
+define i24 @return_zero() {
+    ret i24 0
+}