-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Open
Description
A SIMD variable permute (like i8x16.swizzle) should be optimizable to a constant permute (like i8x16.shuffle) if the input is constant. This type of optimization is already performed for x86 vector operations, but not for WebAssembly vector operations.
This optimization is particularly useful for architecture-generic SIMD, where exposing constant permutes might not be possible depending on the type system.
Take a look at this example code (also on https://godbolt.org/z/6esax48Kr):
#include <wasm_simd128.h>
v128_t reverse(v128_t n) {
v128_t indices = wasm_i8x16_make(
15,
14,
13,
12,
11,
10,
9,
8,
7,
6,
5,
4,
3,
2,
1,
0
);
return wasm_i8x16_swizzle(n, indices);
}I would expect this code to be optimized to:
reverse:
local.get 0
local.get 0
i8x16.shuffle 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
end_functionBut instead, we get:
reverse:
local.get 0
v128.const 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
i8x16.swizzle
end_function