Skip to content

Conversation

@MaxGraey
Copy link
Contributor

@MaxGraey MaxGraey commented Oct 21, 2021

(i32(x) >= 0) & (i32(y) >= 0)   ==>   i32(x | y) >= 0
(i64(x) >= 0) & (i64(y) >= 0)   ==>   i64(x | y) >= 0

(i32(x) >= 0) | (i32(y) >= 0)   ==>   i32(x & y) >= 0
(i64(x) >= 0) | (i64(y) >= 0)   ==>   i64(x & y) >= 0

(i32(x) == -1) & (i32(y) == -1)   ==>   i32(x & y) == -1
(i64(x) == -1) & (i64(y) == -1)   ==>   i64(x & y) == -1

(i32(x) != -1) | (i32(y) != -1)   ==>   i32(x & y) != -1
(i64(x) != -1) | (i64(y) != -1)   ==>   i64(x & y) != -1

Done:

(i32(x) == 0) & (i32(y) == 0)   ==>   i32(x | y) == 0
(i64(x) == 0) & (i64(y) == 0)   ==>   i64(x | y) == 0

(i32(x) != 0) | (i32(y) != 0)   ==>   i32(x | y) != 0
(i64(x) != 0) | (i64(y) != 0)   ==>   i64(x | y) != 0

(i32(x) < 0) | (i32(y) < 0)   ==>   i32(x | y) < 0
(i64(x) < 0) | (i64(y) < 0)   ==>   i64(x | y) < 0

(i32(x) < 0) & (i32(y) < 0)   ==>   i32(x & y) < 0
(i64(x) < 0) & (i64(y) < 0)   ==>   i64(x & y) < 0

@MaxGraey
Copy link
Contributor Author

Fuzzed ITERATION: 10577

@MaxGraey MaxGraey marked this pull request as ready for review October 21, 2021 17:12
@MaxGraey
Copy link
Contributor Author

Refuzzed: ITERATION: 11631

@kripken
Copy link
Member

kripken commented Oct 25, 2021

There are several optimization-related PRs from you @MaxGraey . To organize things, how about opening an issue with a list of them, in the order of most important to review? I think that would make things simpler and more efficient, for me at least.

@MaxGraey
Copy link
Contributor Author

@kripken Sure. I will

kripken pushed a commit that referenced this pull request Oct 26, 2021
…rhs (#4272)

Canonicalize:

(signed)x > -1 ==> x >= 0
(signed)x <= -1 ==> x < 0
(signed)x < 1 ==> x <= 0
(signed)x >= 1 ==> x > 0
(unsigned)x < 1 ==> x == 0
(unsigned)x >= 1 ==> x != 0

This should help #4265, and in general 0 is usually a more
common constant, and reasonable to canonicalize to.
@kripken
Copy link
Member

kripken commented Nov 15, 2021

This is quite a lot of independent patterns in one PR. How about creating a separate PR for each pattern? Some closely-related ones might make sense together in a PR, but when the code for patterns is completely separate then separate PRs is better I think.

@MaxGraey
Copy link
Contributor Author

Hmm, they are all very similar. But I could split this into two separate PRs. Will that be enough? Breaking it down into 9 PRs would be too costly, both in terms of review and fuzzing

@kripken
Copy link
Member

kripken commented Nov 16, 2021

In terms of review, it will be far faster for me if you split it up. The problem with large PRs is that one change ends up causing me to re-read the whole thing.

In terms of fuzzing, I think it's good enough if you've fuzzed them all together here, and don't do any more fuzzing in the new PRs (not unless we actually make significant changes to the logic).

9 PRs would be the right thing, I think. That will be the fastest to review, but even more importantly, it will be the best in terms of bisection. Small commits is the least risky approach, especially with patterns like these where it's possible to miss a corner case. It is a little more work to open the PRs, but I think it is worth it.

@MaxGraey
Copy link
Contributor Author

Alright. I started here: #4333

@MaxGraey MaxGraey closed this Jan 6, 2022
@MaxGraey MaxGraey deleted the opt-binary-two-neg-checks branch January 6, 2022 19:36
kripken pushed a commit that referenced this pull request Jan 26, 2022
…t 7-8) (#4399)

Final part of #4265

(i32(x) >= 0) & (i32(y) >= 0)   ==>   i32(x | y) >= 0
(i64(x) >= 0) & (i64(y) >= 0)   ==>   i64(x | y) >= 0

(i32(x) == -1) & (i32(y) == -1)   ==>   i32(x & y) == -1
(i64(x) == -1) & (i64(y) == -1)   ==>   i64(x & y) == -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants