-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Cranelift: Fix union node bitpacking #7465
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, and thanks for finding this!
Last merge-queue test run seemed to show a real assert failure during compilation:
weird that it only reproduces on the MSRV run and for an integration test? |
I'm going to remove from the queue due to ^ |
It looks like we are creating a union of two values and the values' indices don't fit in the packed representation |
Does anyone know how to run the tokio example, or at least build the wasms that it uses?
|
|
Hm I can't reproduce the assertion failure for that example. But I did find an off-by-one bug in the assertion. It allows |
Okay I was able to repro with the 1.71.0 toolchain. Interestingly enough, it seemed to hang for a while before actually panicking, when the other toolchains ran to completion almost immediately. |
Still going (it is generating a lot of output) but it looks like we've gone into some kind of loop where we are unioning values like
|
Yep, it just finished:
|
e7b8618
to
77ed10a
Compare
Subscribe to Label Action
This issue or pull request has been labeled: "cranelift", "isle"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
I can't reproduce the test failure in CI. I'm also on linux x64 and using rust 1.73. Not sure what is up here. |
77ed10a
to
3b54957
Compare
Hey, I ran the fuzzer on RISC-V overnight on this branch to check if there is something wrong with the RISC-V backend. I don't know if there is yet, but I think I got a reproduction of the issue that was happening in CI earlier. Testcase
Egraphs Result `main`
Egraphs Result `fix-egraph-union`
Edit: This ended up being a RISC-V bug (#7491), but I think it's still worth looking at the testcase, we now spend a bunch of time building values which I'm not sure is intended. |
Thanks for digging into that @afonso360! |
It turns out we have just been taking the newest rewrite's value for a eclass union and never actually comparing costs and taking the value with the minimum cost. Whoops! Fixing this made some test expectations fail, which we resolved by tweaking the cost function to give materializing constants nonzero cost. This way we prefer `-x` to `0 - x`. We also made elaboration function break ties between values with the same cost with the value index. It prefers larger value indices, since the original value's index will be lower than all of its rewritten values' indices. This heuristically prefers rewritten values because we hope our rewrites are all improvements even when the cost function can't show that. Co-Authored-By: Chris Fallin <chris@cfallin.org> Co-Authored-By: Trevor Elliott <telliott@fastly.com>
We generally want to clamp down and avoid runaway behavior here. But there also seems to be some sort of rustc/llvm bug on Rust 1.71 that is causing iteration to wild here. This commit avoids that bug.
ab918f6
to
55e882d
Compare
It turns out we have just been taking the newest rewrite's value for a eclass union and never actually comparing costs and taking the value with the minimum cost. Whoops!
Fixing this made some test expectations fail, which we resolved by tweaking the cost function to give materializing constants nonzero cost. This way we prefer
-x
to0 - x
.We also made elaboration function break ties between values with the same cost with the value index. It prefers larger value indices, since the original value's index will be lower than all of its rewritten values' indices. This heuristically prefers rewritten values because we hope our rewrites are all improvements even when the cost function can't show that.