llvm-project
b861a289 - [WebAssembly] combine `bitmask` with `setcc <X>, 0, setlt` (#179065)

Commit
21 days ago
[WebAssembly] combine `bitmask` with `setcc <X>, 0, setlt` (#179065) The rust `simd_bitmask` intrinsic is UB when the lanes of its input are not either `0` or `!0`, presumably so that the implementation can be more efficient because it could look at any bit. To get the "mask of MSB" behavior of webassembly's `bitmask`, we would like to simply first compare with a zero vector. ```llvm define i32 @example(<2 x i64> noundef %v) { entry: %1 = icmp slt <16 x i8> %v, zeroinitializer %2 = bitcast <16 x i1> %1 to i16 %3 = zext i16 %2 to i32 ret i32 %3 } ``` On x86_64, this additional comparison optimizes away, but for wasm it does not. https://godbolt.org/z/T5sPejocs This PR adds a new combine, so that instead of emitting ```asm example: local.get 0 v128.const 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 i8x16.lt_s i8x16.bitmask end_function ``` we just emit ``` example: local.get 0 i8x16.bitmask end_function ```
Author
Parents
Loading