forked from WebAssembly/binaryen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optimization from
x < 0 || x > POSITIVE_CONST
to `x > POSITIVE_…
…CONST` with unsigned comparison Fixes WebAssembly#6685
- Loading branch information
Showing
2 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. | ||
;; RUN: wasm-opt %s --optimize-instructions -S -o - | filecheck %s | ||
|
||
;; Tests for "x < 0 || x > POSITIVE_CONST ==> x > POSITIVE_CONST (unsigned comparison)" optimization | ||
|
||
(module | ||
;; CHECK: (global $g (mut i32) (i32.const 0)) | ||
(global $g (mut i32) (i32.const 0)) | ||
|
||
;; CHECK: (func $cmp (param $0 i32) (result i32) | ||
;; CHECK-NEXT: (i32.gt_u | ||
;; CHECK-NEXT: (local.get $0) | ||
;; CHECK-NEXT: (i32.const 255) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: ) | ||
(func $cmp (param $0 i32) (result i32) | ||
(i32.or | ||
(i32.lt_s | ||
(local.get $0) | ||
(i32.const 0) | ||
) | ||
(i32.gt_s | ||
(local.get $0) | ||
(i32.const 255) | ||
) | ||
) | ||
) | ||
|
||
;; CHECK: (func $cmp2 (param $0 i32) (result i32) | ||
;; CHECK-NEXT: (i32.or | ||
;; CHECK-NEXT: (i32.lt_s | ||
;; CHECK-NEXT: (local.get $0) | ||
;; CHECK-NEXT: (i32.const 0) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (i32.gt_s | ||
;; CHECK-NEXT: (local.get $0) | ||
;; CHECK-NEXT: (i32.const -255) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: ) | ||
(func $cmp2 (param $0 i32) (result i32) | ||
(i32.or | ||
(i32.lt_s | ||
(local.get $0) | ||
(i32.const 0) | ||
) | ||
(i32.gt_s | ||
(local.get $0) | ||
(i32.const -255) ;; negative number | ||
) | ||
) | ||
) | ||
|
||
;; CHECK: (func $cmp3 (param $0 i32) (result i32) | ||
;; CHECK-NEXT: (i32.or | ||
;; CHECK-NEXT: (i32.lt_s | ||
;; CHECK-NEXT: (local.get $0) | ||
;; CHECK-NEXT: (i32.const 10) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (i32.gt_s | ||
;; CHECK-NEXT: (local.get $0) | ||
;; CHECK-NEXT: (i32.const 255) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: ) | ||
(func $cmp3 (param $0 i32) (result i32) | ||
(i32.or | ||
(i32.lt_s | ||
(local.get $0) | ||
(i32.const 10) ;; note this | ||
) | ||
(i32.gt_s | ||
(local.get $0) | ||
(i32.const 255) | ||
) | ||
) | ||
) | ||
|
||
;; CHECK: (func $set_global_and_return (param $x i32) (result i32) | ||
;; CHECK-NEXT: (global.set $g | ||
;; CHECK-NEXT: (local.get $x) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (local.get $x) | ||
;; CHECK-NEXT: ) | ||
(func $set_global_and_return (param $x i32) (result i32) | ||
(global.set $g (local.get $x)) ;; side-effect | ||
(local.get $x) | ||
) | ||
|
||
;; CHECK: (func $cmp4 (result i32) | ||
;; CHECK-NEXT: (i32.or | ||
;; CHECK-NEXT: (i32.lt_s | ||
;; CHECK-NEXT: (call $set_global_and_return | ||
;; CHECK-NEXT: (i32.const 10) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (i32.const 0) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (i32.gt_s | ||
;; CHECK-NEXT: (call $set_global_and_return | ||
;; CHECK-NEXT: (i32.const 10) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (i32.const 255) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: ) | ||
(func $cmp4 (result i32) | ||
(i32.or | ||
(i32.lt_s | ||
(call $set_global_and_return (i32.const 10)) ;; x with side-effect | ||
(i32.const 0) | ||
) | ||
(i32.gt_s | ||
(call $set_global_and_return (i32.const 10)) | ||
(i32.const 255) | ||
) | ||
) | ||
) | ||
|
||
;; CHECK: (func $cmp5 (param $0 i32) (param $1 i32) (result i32) | ||
;; CHECK-NEXT: (i32.gt_u | ||
;; CHECK-NEXT: (local.get $0) | ||
;; CHECK-NEXT: (i32.const 255) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: ) | ||
(func $cmp5 (param $0 i32) (param $1 i32) (result i32) | ||
(i32.or | ||
(i32.lt_s | ||
(local.get $0) | ||
(i32.const 0) | ||
) | ||
(i32.gt_s | ||
(local.get $1) ;; note this | ||
(i32.const 255) | ||
) | ||
) | ||
) | ||
|
||
;; CHECK: (func $cmp6 (param $0 i32) (param $1 i32) (result i32) | ||
;; CHECK-NEXT: (i32.or | ||
;; CHECK-NEXT: (i32.lt_s | ||
;; CHECK-NEXT: (local.get $0) | ||
;; CHECK-NEXT: (i32.const 0) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: (i32.gt_s | ||
;; CHECK-NEXT: (local.get $0) | ||
;; CHECK-NEXT: (local.get $1) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: ) | ||
(func $cmp6 (param $0 i32) (param $1 i32) (result i32) | ||
(i32.or | ||
(i32.lt_s | ||
(local.get $0) | ||
(i32.const 0) | ||
) | ||
(i32.gt_s | ||
(local.get $0) | ||
(local.get $1) ;; non-constant | ||
) | ||
) | ||
) | ||
) |