diff options
author | Alon Zakai <azakai@google.com> | 2021-07-13 15:00:20 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-13 15:00:20 -0700 |
commit | b68691e826a46d1b03b27c552b1f5b7f51f92665 (patch) | |
tree | 4f852ce51315e86e1bd2600af85fba7940f34a54 | |
parent | aafd1bf1be09d6368127f9878ab1779cc258f526 (diff) | |
download | binaryen-b68691e826a46d1b03b27c552b1f5b7f51f92665.tar.gz binaryen-b68691e826a46d1b03b27c552b1f5b7f51f92665.tar.bz2 binaryen-b68691e826a46d1b03b27c552b1f5b7f51f92665.zip |
Partially fix Precompute on SIMD (#3983)
We had the logic in only one place.
-rw-r--r-- | src/passes/Precompute.cpp | 18 | ||||
-rw-r--r-- | test/passes/precompute_all-features.txt | 9 | ||||
-rw-r--r-- | test/passes/precompute_all-features.wast | 7 |
3 files changed, 24 insertions, 10 deletions
diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp index a832c9e85..fa6e8e9ed 100644 --- a/src/passes/Precompute.cpp +++ b/src/passes/Precompute.cpp @@ -172,17 +172,8 @@ struct Precompute if (Properties::isConstantExpression(curr) || curr->is<Nop>()) { return; } - // Until engines implement v128.const and we have SIMD-aware optimizations - // that can break large v128.const instructions into smaller consts and - // splats, do not try to precompute v128 expressions. - if (curr->type.isVector()) { - return; - } // try to evaluate this into a const Flow flow = precomputeExpression(curr); - if (flow.getType().hasVector()) { - return; - } if (!canEmitConstantFor(flow.values)) { return; } @@ -236,6 +227,12 @@ private: // Precompute an expression, returning a flow, which may be a constant // (that we can replace the expression with if replaceExpression is set). Flow precomputeExpression(Expression* curr, bool replaceExpression = true) { + // Until engines implement v128.const and we have SIMD-aware optimizations + // that can break large v128.const instructions into smaller consts and + // splats, do not try to precompute v128 expressions. + if (curr->type.isVector()) { + return Flow(NONCONSTANT_FLOW); + } Flow flow; try { flow = @@ -250,6 +247,9 @@ private: !canEmitConstantFor(flow.values)) { return Flow(NONCONSTANT_FLOW); } + if (flow.getType().hasVector()) { + return Flow(NONCONSTANT_FLOW); + } return flow; } diff --git a/test/passes/precompute_all-features.txt b/test/passes/precompute_all-features.txt index b707f4248..dc93f90e4 100644 --- a/test/passes/precompute_all-features.txt +++ b/test/passes/precompute_all-features.txt @@ -1,8 +1,8 @@ (module (type $none_=>_none (func)) (type $none_=>_i32 (func (result i32))) - (type $none_=>_f64 (func (result f64))) (type $none_=>_v128 (func (result v128))) + (type $none_=>_f64 (func (result f64))) (type $0 (func (param i32))) (type $none_=>_i32_i64 (func (result i32 i64))) (type $none_=>_externref (func (result externref))) @@ -222,6 +222,13 @@ (i32.const 0) ) ) + (func $no-simd-precompute_2 (result v128) + (i32x4.extadd_pairwise_i16x8_s + (i32x4.splat + (i32.const 0) + ) + ) + ) (func $no-simd-precompute-if (result v128) (return (i32x4.splat diff --git a/test/passes/precompute_all-features.wast b/test/passes/precompute_all-features.wast index 1275524e0..e306be495 100644 --- a/test/passes/precompute_all-features.wast +++ b/test/passes/precompute_all-features.wast @@ -329,6 +329,13 @@ (i32.const 0) ) ) + (func $no-simd-precompute_2 (result v128) + (i32x4.extadd_pairwise_i16x8_s + (i32x4.splat + (i32.const 0) + ) + ) + ) (func $no-simd-precompute-if (result v128) (return (i32x4.splat |