diff options
author | Max Graey <maxgraey@gmail.com> | 2021-08-02 16:30:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-02 13:30:26 +0000 |
commit | f35f02c1ce1b3129aa83d2dddeababd414c1ca8f (patch) | |
tree | 52b70c4193f77d63615f6571458248cf055c62a8 /test | |
parent | 512033eed52fff82274650aca7d7374b4b305551 (diff) | |
download | binaryen-f35f02c1ce1b3129aa83d2dddeababd414c1ca8f.tar.gz binaryen-f35f02c1ce1b3129aa83d2dddeababd414c1ca8f.tar.bz2 binaryen-f35f02c1ce1b3129aa83d2dddeababd414c1ca8f.zip |
[JS] Add a new OptimizeForJS pass (#4033)
Add a new OptimizeForJS pass which contains rewriting rules specific to JavaScript.
LLVM usually lowers x != 0 && (x & (x - 1)) == 0 (isPowerOf2) to popcnt(x) == 1 which is ok for wasm and other targets but is quite expensive for JavaScript. In this PR we lower the popcnt pattern back to the isPowerOf2 pattern.
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/help/optimization-opts.test | 3 | ||||
-rw-r--r-- | test/lit/passes/optimize-for-js.wast | 54 |
2 files changed, 57 insertions, 0 deletions
diff --git a/test/lit/help/optimization-opts.test b/test/lit/help/optimization-opts.test index 0d4ed48a8..c6d45332d 100644 --- a/test/lit/help/optimization-opts.test +++ b/test/lit/help/optimization-opts.test @@ -347,6 +347,9 @@ ;; CHECK-NEXT: load/store offsets, propagating ;; CHECK-NEXT: them across locals too ;; CHECK-NEXT: +;; CHECK-NEXT: --optimize-for-js early optimize of the +;; CHECK-NEXT: instruction combinations for js +;; CHECK-NEXT: ;; CHECK-NEXT: --optimize-instructions optimizes instruction ;; CHECK-NEXT: combinations ;; CHECK-NEXT: diff --git a/test/lit/passes/optimize-for-js.wast b/test/lit/passes/optimize-for-js.wast new file mode 100644 index 000000000..c123011fc --- /dev/null +++ b/test/lit/passes/optimize-for-js.wast @@ -0,0 +1,54 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. +;; RUN: wasm-opt %s --optimize-for-js -all -S -o - \ +;; RUN: | filecheck %s + +(module + ;; CHECK: (func $is-power-of-2_32 (param $x i32) (result i32) + ;; CHECK-NEXT: (i32.and + ;; CHECK-NEXT: (i32.eqz + ;; CHECK-NEXT: (i32.eqz + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (i32.eqz + ;; CHECK-NEXT: (i32.and + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (i32.sub + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $is-power-of-2_32 (param $x i32) (result i32) + (i32.eq + (i32.popcnt (local.get $x)) + (i32.const 1) + ) + ) + ;; CHECK: (func $is-power-of-2_64 (param $x i64) (result i32) + ;; CHECK-NEXT: (i32.and + ;; CHECK-NEXT: (i32.eqz + ;; CHECK-NEXT: (i64.eqz + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (i64.eqz + ;; CHECK-NEXT: (i64.and + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (i64.sub + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: (i64.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $is-power-of-2_64 (param $x i64) (result i32) + (i64.eq + (i64.popcnt (local.get $x)) + (i64.const 1) + ) + ) +) |