Commit d95b1645 authored by Milad Fa's avatar Milad Fa Committed by Commit Bot

PPC/s390: [wasm-simd] Canonicalize shuffles when creating TurboFan graph

Port d16eefe0

Original Commit Message:

    We currently canonicalize shuffles in the architecture specific
    instruction selector. This has the drawback that if we want to pattern
    match on nodes that have a shuffle as input, they need to individually
    canonicalize the shuffle. There can also be a subtle bug if we
    canonicalize the same shuffle node twice (see bug for details).

    This moves the canonicalization to "construction time", in
    wasm-compiler, when building the graph. As such, any pattern matches in
    instruction-selector will only need to deal with canonicalized shuffles.

    We introduce a new kind of parameter for shuffle nodes,
    ShuffleParameter, to store the 16 bytes plus a bool indicating if this
    is a swizzle. A swizzle essentially: inputs to the shuffle are the same
    or all indices only touch 1 input. We calculate this when
    canonicalizing, so store this bit of information inside of the node's
    parameter.

    We update the tests in x64 to handle special cases where, even though
    the node's inputs are not swapped (due to canonicalization), they need
    to be swapped for the specific instruction selected (e.g. palignr). The
    test data also contains canonicalized shuffles, so we have to manually
    canonicalize them.

R=zhin@chromium.org, joransiu@ca.ibm.com, junyan@redhat.com, midawson@redhat.com
BUG=
LOG=N

Change-Id: I9872fcdaa06739c8972f02d81e77bcbf372126c2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2773138Reviewed-by: 's avatarJunliang Yan <junyan@redhat.com>
Commit-Queue: Milad Fa <mfarazma@redhat.com>
Cr-Commit-Position: refs/heads/master@{#73512}
parent c4b44d5d
......@@ -2427,7 +2427,6 @@ SIMD_VISIT_PMIN_MAX(F32x4Pmax)
void InstructionSelector::VisitI8x16Shuffle(Node* node) {
uint8_t shuffle[kSimd128Size];
auto param = ShuffleParameterOf(node->op());
bool is_swizzle = param.is_swizzle();
base::Memcpy(shuffle, param.imm().data(), kSimd128Size);
PPCOperandGenerator g(this);
Node* input0 = node->InputAt(0);
......
......@@ -2709,9 +2709,8 @@ SIMD_VISIT_PMIN_MAX(F32x4Pmax)
#if V8_ENABLE_WEBASSEMBLY
void InstructionSelector::VisitI8x16Shuffle(Node* node) {
uint8_t shuffle[kSimd128Size];
uint8_t* shuffle_p = &shuffle[0];
bool is_swizzle;
CanonicalizeShuffle(node, shuffle, &is_swizzle);
auto param = ShuffleParameterOf(node->op());
base::Memcpy(shuffle, param.imm().data(), kSimd128Size);
S390OperandGenerator g(this);
Node* input0 = node->InputAt(0);
Node* input1 = node->InputAt(1);
......@@ -2725,13 +2724,12 @@ void InstructionSelector::VisitI8x16Shuffle(Node* node) {
? max_index - current_index
: total_lane_count - current_index + max_index);
}
shuffle_p = &shuffle_remapped[0];
Emit(kS390_I8x16Shuffle, g.DefineAsRegister(node),
g.UseUniqueRegister(input0), g.UseUniqueRegister(input1),
g.UseImmediate(wasm::SimdShuffle::Pack4Lanes(shuffle_p)),
g.UseImmediate(wasm::SimdShuffle::Pack4Lanes(shuffle_p + 4)),
g.UseImmediate(wasm::SimdShuffle::Pack4Lanes(shuffle_p + 8)),
g.UseImmediate(wasm::SimdShuffle::Pack4Lanes(shuffle_p + 12)));
g.UseImmediate(wasm::SimdShuffle::Pack4Lanes(shuffle_remapped)),
g.UseImmediate(wasm::SimdShuffle::Pack4Lanes(shuffle_remapped + 4)),
g.UseImmediate(wasm::SimdShuffle::Pack4Lanes(shuffle_remapped + 8)),
g.UseImmediate(wasm::SimdShuffle::Pack4Lanes(shuffle_remapped + 12)));
}
#else
void InstructionSelector::VisitI8x16Shuffle(Node* node) { UNREACHABLE(); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment