Skip to content

Compiler: optimize (x | 0) >>> 0 #1177

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 1 commit into from
Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Features/Changes
* Compiler: static evaluation of backend_type
* Compiler: speedup emitting js files.
* Compiler: simplify (a | 0) >>> 0 into (a >>> 0)
* Lib: add messageEvent to Dom_html
* Lib: add PerformanceObserver API
* Lib: add CSSStyleDeclaration.{setProperty, getPropertyValue, getPropertyPriority, removeProperty}
Expand Down
5 changes: 5 additions & 0 deletions compiler/lib/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ let to_int cx = J.EBin (J.Bor, cx, int 0)
let unsigned' x = J.EBin (J.Lsr, x, int 0)

let unsigned x =
let x =
match x with
| J.EBin (J.Bor, x, J.ENum maybe_zero) when J.Num.is_zero maybe_zero -> x
| _ -> x
in
let pos_int32 =
match x with
| J.ENum num -> ( try Int32.(J.Num.to_int32 num >= 0l) with _ -> false)
Expand Down