diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp @@ -851,6 +851,13 @@ Args.push_back(Reg); } + unsigned CalleeReg = 0; + if (!IsDirect) { + CalleeReg = getRegForValue(Call->getCalledValue()); + if (!CalleeReg) + return false; + } + auto MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc)); if (!IsVoid) @@ -858,12 +865,8 @@ if (IsDirect) MIB.addGlobalAddress(Func); - else { - unsigned Reg = getRegForValue(Call->getCalledValue()); - if (Reg == 0) - return false; - MIB.addReg(Reg); - } + else + MIB.addReg(CalleeReg); for (unsigned ArgReg : Args) MIB.addReg(ArgReg);