From 6877df25a05aa6dd4f1e8c34e1d4936e8b0e5ee9 Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Fri, 31 Jul 2015 18:13:27 +0000 Subject: [PATCH] WebAssembly: handle unused function arguments. Subscribers: llvm-commits, sunfish, jfb Differential Revision: http://reviews.llvm.org/D11684 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243770 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../WebAssembly/WebAssemblyISelLowering.cpp | 10 ++++++---- test/CodeGen/WebAssembly/unused-argument.ll | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 test/CodeGen/WebAssembly/unused-argument.ll diff --git a/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp index 639e19a52dc..90a4078b407 100644 --- a/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp +++ b/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp @@ -191,11 +191,13 @@ SDValue WebAssemblyTargetLowering::LowerFormalArguments( fail(DL, DAG, "WebAssembly hasn't implemented split arguments"); if (In.VT != MVT::i32) fail(DL, DAG, "WebAssembly hasn't implemented non-i32 arguments"); - if (!In.Used) - fail(DL, DAG, "WebAssembly hasn't implemented unused arguments"); // FIXME Do something with In.getOrigAlign()? - InVals.push_back(DAG.getNode(WebAssemblyISD::ARGUMENT, DL, In.VT, - DAG.getTargetConstant(ArgNo++, DL, MVT::i32))); + InVals.push_back( + In.Used + ? DAG.getNode(WebAssemblyISD::ARGUMENT, DL, In.VT, + DAG.getTargetConstant(ArgNo, DL, MVT::i32)) + : DAG.getNode(ISD::UNDEF, DL, In.VT)); + ++ArgNo; } return Chain; diff --git a/test/CodeGen/WebAssembly/unused-argument.ll b/test/CodeGen/WebAssembly/unused-argument.ll new file mode 100644 index 00000000000..5e546f7eddf --- /dev/null +++ b/test/CodeGen/WebAssembly/unused-argument.ll @@ -0,0 +1,20 @@ +; RUN: llc < %s -asm-verbose=false | FileCheck %s + +; Make sure that argument offsets are correct even if some arguments are unused. + +target datalayout = "e-p:32:32-i64:64-v128:8:128-n32:64-S128" +target triple = "wasm32-unknown-unknown" + +; CHECK-LABEL: unused_first: +; CHECK-NEXT: (setlocal @0 (argument 1)) +; CHECK-NEXT: (RETURN @0) +define i32 @unused_first(i32 %x, i32 %y) { + ret i32 %y +} + +; CHECK-LABEL: unused_second: +; CHECK-NEXT: (setlocal @0 (argument 0)) +; CHECK-NEXT: (RETURN @0) +define i32 @unused_second(i32 %x, i32 %y) { + ret i32 %x +} -- 2.34.1