Skip to content

OptimizeInstruction: Optimize any boolean & (No overlap with boolean's LSB) ==> 0 #7505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
May 23, 2025
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b67c4ac
opt for #7481
xuruiyang2002 Apr 16, 2025
340fd1b
tests
xuruiyang2002 Apr 16, 2025
6aab029
refactor to be generalized
xuruiyang2002 Apr 19, 2025
11992ac
update test due to refactoring
xuruiyang2002 Apr 19, 2025
bfdc24c
No need for special-cased 0
xuruiyang2002 Apr 24, 2025
27ac17f
Avoid redundant replaceCurrent
xuruiyang2002 Apr 24, 2025
2f2dbfb
And is commutative
xuruiyang2002 Apr 24, 2025
a8216a0
Update test
xuruiyang2002 Apr 24, 2025
2bbd847
Update test
xuruiyang2002 Apr 24, 2025
dad3fd5
Update test
xuruiyang2002 Apr 24, 2025
51196f8
Deal with cornor case
xuruiyang2002 Apr 24, 2025
131a423
Add cornor case
xuruiyang2002 Apr 24, 2025
0f09450
Refactor
xuruiyang2002 Apr 24, 2025
37653fe
Update src/passes/OptimizeInstructions.cpp
xuruiyang2002 Apr 29, 2025
0d8c6ad
Avoid redundant code
xuruiyang2002 May 1, 2025
f6de81a
Update test
xuruiyang2002 May 1, 2025
3f900fe
Adjust comments
xuruiyang2002 May 1, 2025
4dfe6ee
Adjust comments
xuruiyang2002 May 1, 2025
e5bffdf
Update src/passes/OptimizeInstructions.cpp
xuruiyang2002 May 2, 2025
4cc33e4
Update src/passes/OptimizeInstructions.cpp
xuruiyang2002 May 2, 2025
fb14118
Update src/passes/OptimizeInstructions.cpp
xuruiyang2002 May 2, 2025
27608e9
Update test
xuruiyang2002 May 2, 2025
4ae987c
Concrete type
xuruiyang2002 May 16, 2025
4eadb01
Update
xuruiyang2002 May 16, 2025
7b7a420
Use isNumber instead of isConcrete
xuruiyang2002 May 16, 2025
a612db0
Simplify tests
xuruiyang2002 May 23, 2025
8f663bb
Update test/lit/passes/optimize-instructions-mvp.wast
xuruiyang2002 May 23, 2025
b57c369
Update test/lit/passes/optimize-instructions-mvp.wast
xuruiyang2002 May 23, 2025
d1c0cf6
Update test/lit/passes/optimize-instructions-mvp.wast
xuruiyang2002 May 23, 2025
a3f26d9
Update test/lit/passes/optimize-instructions-mvp.wast
xuruiyang2002 May 23, 2025
440b963
Update test
xuruiyang2002 May 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add cornor case
  • Loading branch information
xuruiyang2002 committed Apr 24, 2025
commit 131a423d5054eb52a5ee127b4b35d1098bb75413
120 changes: 120 additions & 0 deletions test/lit/passes/optimize-instructions-mvp.wast
Original file line number Diff line number Diff line change
Expand Up @@ -17770,4 +17770,124 @@
(i32.const 1)
)
)
;; CHECK: (func $no-overlapping-bits-corner-case (param $x i32) (param $y i64)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.and
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i64.and
;; CHECK-NEXT: (local.get $y)
;; CHECK-NEXT: (i64.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.and
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i64.and
;; CHECK-NEXT: (local.get $y)
;; CHECK-NEXT: (i64.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i64.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i64.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i64.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.and
;; CHECK-NEXT: (i32.const -2147483647)
;; CHECK-NEXT: (i32.const 2147483647)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i64.and
;; CHECK-NEXT: (i64.const 2147483649)
;; CHECK-NEXT: (i64.const 2147483647)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $no-overlapping-bits-corner-case (param $x i32) (param $y i64)
;; optimizeAndNoOverlappingBits will simplify AND operations where
;; Bitwise AND of a value with bits in [0, n) and a constant with no bits in
;; [0, n) always yields 0. Replace with zero.
;; Note: after swapping the operands, it also satisfies the commutative law.

;; Unknown, not optimized
(drop
(i32.and
(local.get $x)
(i32.const 1)
)
)
(drop
(i64.and
(local.get $y)
(i64.const 1)
)
)
(drop
(i32.and
(i32.const 1)
(local.get $x)
)
)
(drop
(i64.and
(i64.const 1)
(local.get $y)
)
)
;; No any bit overlapping, optimized
(drop
(i32.and
(i32.const 0x80000000)
(i32.const 0x7fffffff)
)
)
(drop
(i64.and
(i64.const 2)
(i64.const 1)
)
)
(drop
(i64.and
(i64.const 0x80000000)
(i64.const 0x7fffffff)
)
)
(drop
(i64.and
(i64.const 0x8000000000000000)
(i64.const 0x7fffffffffffffff)
)
)
;; Just one bit overlapping, not optimized
(drop
(i32.and
(i32.const 0x80000001)
(i32.const 0x7fffffff)
)
)
(drop
(i64.and
(i64.const 0x80000001)
(i64.const 0x7fffffff)
)
)
)
)
Loading