<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63388>63388</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[WASM] "signext" attribute leads miscompilation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
doit-man
</td>
</tr>
</table>
<pre>
```
define i32 @foo(i1 signext noundef %cond, i32 noundef %y) {
%e = zext i1 %cond to i32
%r = sub i32 %y, %e
ret i32 %r
}
```
Compiling with ``` llc --march=wasm32 -filetype=obj {ll} -o {obj} ```, ```wasm-ld --no-entry --export-all --allow-undefined {obj} -o {wasm}```
```
(module
(type (;0;) (func))
(type (;1;) (func (param i32 i32) (result i32)))
(func $__wasm_call_ctors (type 0))
(func $src (type 1) (param i32 i32) (result i32)
local.get 1
local.get 0
i32.add)
(func $tgt (type 1) (param i32 i32) (result i32)
i32.const 77)
(memory (;0;) 2)
(global $__stack_pointer (mut i32) (i32.const 66560))
(global (;1;) i32 (i32.const 1024))
(global (;2;) i32 (i32.const 1024))
(global (;3;) i32 (i32.const 1024))
(global (;4;) i32 (i32.const 66560))
(global (;5;) i32 (i32.const 1024))
(global (;6;) i32 (i32.const 66560))
(global (;7;) i32 (i32.const 131072))
(global (;8;) i32 (i32.const 0))
(global (;9;) i32 (i32.const 1))
(export "memory" (memory 0))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
(export "src" (func $src))
(export "tgt" (func $tgt))
(export "__dso_handle" (global 1))
(export "__data_end" (global 2))
(export "__stack_low" (global 3))
(export "__stack_high" (global 4))
(export "__global_base" (global 5))
(export "__heap_base" (global 6))
(export "__heap_end" (global 7))
(export "__memory_base" (global 8))
(export "__table_base" (global 9)))
```
The first argument of the function should subtract the second argument, but in wasm, it appears to be performing addition.
``` signext ``` attribute leads this miscompilation. whitout ``` signext ``` compilation is correct.
</pre>
<img width="1px" height="1px" alt="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