-
Notifications
You must be signed in to change notification settings - Fork 786
Optimize comparisons of adjusted values #5008
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
Comments
Another example from rule (i32.lt_s
(i32.shr_s
(local.get $0)
(i32.const 1)
)
(i32.const 12)
)
=->
(i32.lt_s
(local.get $0)
(i32.const 24)
) |
This also happens with floats, though there we may need fast-math, e.g. (f32.ge
(f32.add
(local.get $0)
(f32.const -9.99999993922529e-09)
)
(f32.const 0)
)
=->
(f32.gt
(local.get $0)
(f32.const 9.99999905104687e-09)
) (rule #21) |
Another example: (i32.gt_u
(i32.add
(i32.shr_u
(local.get $0)
(i32.const 1)
)
(i32.const 8)
)
(i32.const 65535)
) The add's left operand is less than 32 bits, so it cannot overflow even with an added 8, and so edit: This and related things seem to be the top superoptimizer finding for Java and Dart, followed by #5008 (comment) |
E.g. x + C1 > C2 ==> x > (C2-C1) We do need to be careful of overflows in either the add on the left or the proposed subtract on the right. In the latter case, we can at least do x + C1 > C2 ==> x + (C1-C2) > 0 Helps #5008 (but more patterns remain). Found by the superoptimizer #4994. This was the top suggestion for Java and Dart.
All comparisons |
E.g.
Instead of dividing by 2 and then comparing, we can compare the original value.
More variations: add a constant, or both add and multiply/divide.
Found by the superoptimizer #4994 (for comparison to other findings: rule
#8
, benefit30492
).The text was updated successfully, but these errors were encountered: