Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp @@ -191,11 +191,13 @@ 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; Index: llvm/trunk/test/CodeGen/WebAssembly/unused-argument.ll =================================================================== --- llvm/trunk/test/CodeGen/WebAssembly/unused-argument.ll +++ llvm/trunk/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 +}