diff options
author | Pavel Verigo <58272683+pavelverigo@users.noreply.github.com> | 2025-05-06 23:16:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-06 14:16:35 -0700 |
commit | 9d89b05f1147dc442794186f505e30a27ffe75a7 (patch) | |
tree | b7515a559619ebfa1a759b085e0e8ba4af4470f5 /llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp | |
parent | 5c3ef62f64cc379b8c5a4cf23bcaf019d398fcc4 (diff) | |
download | llvm-9d89b05f1147dc442794186f505e30a27ffe75a7.zip llvm-9d89b05f1147dc442794186f505e30a27ffe75a7.tar.gz llvm-9d89b05f1147dc442794186f505e30a27ffe75a7.tar.bz2 |
[WebAssembly] Fix trunc in FastISel (#138479)
Previous logic did not handle the case where the result bit size was
between 32 and 64 bits inclusive. I updated the if-statements for more
precise handling.
An alternative solution would have been to abort FastISel in case the
result type is not legal for FastISel.
Resolves: #64222.
This PR began as an investigation into the root cause of
https://github.com/ziglang/zig/issues/20966.
Godbolt link showing incorrect codegen on 20.1.0:
https://godbolt.org/z/cEr4vY7d4.
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp index 78c6a41..b2ea784 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) |