cfallin opened PR #5409 from egraph-issue-5405
to main
:
This fixes #5405.
In the egraph mid-end's optimization rules, we were rewriting e.g. imuls of two iconsts to an iconst of the result, but without masking off the high bits (beyond the result type's width). This was producing iconsts with set high bits beyond their types' width, which is not legal.
In addition, this PR adds some optimizations to the algebraic rules to recognize e.g.
x == x
(and all other integer comparison operators) and resolve to 1 or 0 as appropriate.<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
cfallin requested elliottt for a review on PR #5409.
cfallin requested fitzgen for a review on PR #5409.
cfallin requested jameysharp for a review on PR #5409.
cfallin updated PR #5409 from egraph-issue-5405
to main
.
jameysharp submitted PR review.
jameysharp submitted PR review.
jameysharp created PR review comment:
I don't believe this works when
ty.bits()
is exactly 64.Instead you could use
u64::MAX >> (64 - ty.bits())
, since we knowty.bits()
is never 0.Alternatively, since any bit-width that's no smaller than 64 doesn't need any masking, you could remove the assert and use something like:
if let Some(bit) = 1u64.checked_shl(ty.bits()) { Imm64::new((x & (bit - 1)) as i64) } else { Imm64::new(x as i64) }
cfallin submitted PR review.
cfallin created PR review comment:
Ah, yes, sorry for missing that! I prefer the version without conditionals (the first expression you gave) so I've gone with that.
cfallin updated PR #5409 from egraph-issue-5405
to main
.
jameysharp submitted PR review.
jameysharp created PR review comment:
I don't understand pulling
ty.bits() == 64
out as a special case if you're using the right-shift version below.u64::MAX >> 0
should be a correct mask for this case.
cfallin updated PR #5409 from egraph-issue-5405
to main
.
cfallin submitted PR review.
cfallin created PR review comment:
Argh, yeah, I wrote it the conditionalized way first and then decided I liked the right-shift variant better, but only updated locally and didn't actually delete the conditional. I think I've found the rest of my brain now; sorry about that...
jameysharp submitted PR review.
cfallin has enabled auto merge for PR #5409.
cfallin merged PR #5409.
Last updated: Nov 22 2024 at 17:03 UTC