Issue 202366
Summary [WebAssembly] Suboptimal lowering of int128 operations
Labels new issue
Assignees
Reporter anematode
    https://godbolt.org/z/bhf67j17j

```cpp
#include <stdint.h>

uint32_t mul_hi(uint64_t a, uint32_t b) {
    return (__int128)(a) * (__int128)(b) >> 64;
}
```

Seems like we always lower int128 multiplies to a library call even if the operands have a restricted range and could be expressed in a much simpler sequence.

```wat
mul_hi(unsigned long long, unsigned int):
 global.get      __stack_pointer
        i32.const       16
        i32.sub 
        local.tee       2
        global.set      __stack_pointer
 local.get       2
        local.get       1
        i64.extend_i32_u
 i64.const       0
        local.get       0
        i64.const       0
 call    __multi3
        local.get       2
        i32.load        8
 local.set       1
        local.get       2
        i32.const 16
        i32.add 
        global.set      __stack_pointer
 local.get       1
        end_function
```

Found this while working on [this port](https://github.com/official-stockfish/Stockfish/pull/6875/changes#diff-e428c7a719856e301ac3978f5bb612bbafba0494838d9ec4c7fc5fbda8451410R368). 
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to