From 7f57949cd0dfbfc80f70aa4808bd52e53a37c661 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 17 Apr 2018 20:46:42 +0000 Subject: [PATCH] [WebAssembly] Teach fast-isel to gracefully recover from illegal return types. Fixes PR36564. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330215 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/WebAssembly/WebAssemblyFastISel.cpp | 8 ++++++-- test/CodeGen/WebAssembly/fast-isel-i24.ll | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/CodeGen/WebAssembly/fast-isel-i24.ll diff --git a/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/lib/Target/WebAssembly/WebAssemblyFastISel.cpp index f3ee6e70822..c13dd7a48a7 100644 --- a/lib/Target/WebAssembly/WebAssemblyFastISel.cpp +++ b/lib/Target/WebAssembly/WebAssemblyFastISel.cpp @@ -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/test/CodeGen/WebAssembly/fast-isel-i24.ll b/test/CodeGen/WebAssembly/fast-isel-i24.ll new file mode 100644 index 00000000000..d3823f9869b --- /dev/null +++ b/test/CodeGen/WebAssembly/fast-isel-i24.ll @@ -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 +} -- 2.11.0