<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64222>64222</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[wasm] trunc + sadd.with.overflow produces output that does not validate
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jacobly0
</td>
</tr>
</table>
<pre>
```llvm
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
target triple = "wasm32-unknown-wasi"
define i1 @entry(i64 %x) {
%truncated = trunc i64 %x to i48
%tuple = call fastcc { i48, i1 } @llvm.sadd.with.overflow.i48(i48 %truncated, i48 1)
%overflow = extractvalue { i48, i1 } %tuple, 1
ret i1 %overflow
}
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i48, i1 } @llvm.sadd.with.overflow.i48(i48, i48) #0
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```
```
$ clang --version
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 239777c8616a614531bed68fff2eaa0c97721cb3)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/jacob/prg/llvm/main/build-Debug/bin
$ clang -target wasm32-wasi -S repro.ll -o -
...
.type entry,@function
entry: # @entry
.functype entry (i64) -> (i32)
.local i32, i64, i64, i64, i64, i64, i64, i64, i32
# %bb.0:
local.get 0
i32.wrap_i64
local.set 1
i64.const 16
local.set 2
local.get 1
local.get 2
i64.shl
...
$ clang -nostdlib -target wasm32-wasi repro.ll -Wl,--entry=entry -o repro.wasm
$ wasm2wat repro.wasm
repro.wasm:0000050: error: type mismatch in i64.shl, expected [i64, i64] but got [i32, i64]
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVU2P4ygQ_TXkUrJlF_485JDubKQ9z0p7HGEgCTMYLMCdzr9fg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