diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp index 78c6a41624291..b2ea784057780 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp @@ -992,7 +992,10 @@ bool WebAssemblyFastISel::selectTrunc(const Instruction *I) { if (Reg == 0) return false; - if (Trunc->getOperand(0)->getType()->isIntegerTy(64)) { + unsigned FromBitWidth = Trunc->getOperand(0)->getType()->getIntegerBitWidth(); + unsigned ToBitWidth = Trunc->getType()->getIntegerBitWidth(); + + if (ToBitWidth <= 32 && (32 < FromBitWidth && FromBitWidth <= 64)) { Register Result = createResultReg(&WebAssembly::I32RegClass); BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(WebAssembly::I32_WRAP_I64), Result) diff --git a/llvm/test/CodeGen/WebAssembly/fast-isel-pr138479.ll b/llvm/test/CodeGen/WebAssembly/fast-isel-pr138479.ll new file mode 100644 index 0000000000000..2676000b968c3 --- /dev/null +++ b/llvm/test/CodeGen/WebAssembly/fast-isel-pr138479.ll @@ -0,0 +1,15 @@ +; RUN: llc < %s -asm-verbose=false -fast-isel -fast-isel-abort=1 -verify-machineinstrs | FileCheck %s + +target triple = "wasm32-unknown-unknown" + +declare void @extern48(i48) + +; CHECK-LABEL: call_trunc_i64_to_i48: +; CHECK: local.get 0 +; CHECK-NEXT: call extern48 +; CHECK-NEXT: end_function +define void @call_trunc_i64_to_i48(i64 %x) { + %x48 = trunc i64 %x to i48 + call void @extern48(i48 %x48) + ret void +}