Skip to content
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

A DSL for Peephole Transformation Rules of Integer Operations in the PyPy JIT | PyPy #144

Open
utterances-bot opened this issue Nov 10, 2024 · 4 comments

Comments

@utterances-bot
Copy link

A DSL for Peephole Transformation Rules of Integer Operations in the PyPy JIT | PyPy

https://www.pypy.org/posts/2024/10/jit-peephole-dsl.html

Copy link

In the section "Computing constants and other intermediate results", should not C = C1 + C1 be C = C1 + C2?

@arigo
Copy link
Member

arigo commented Nov 10, 2024

In mul_lshift: int_mul(x, int_lshift(1, y)), it's unclear why you need to add the rule check y.known_ge_const(0) and y.known_le_const(LONG_BIT). I think that if that check is not satisfied, then we can look at it in two ways:

  • either the int_lshift(1, y) would give undefined results anyway, and adding the check doesn't change the fact that the incoming instruction was already undefined;
  • or we say that int_lshift is well-defined and in practice works by considering only the lower bits of y, and in that case, then the replacement is valid even without the check.

@cfbolz
Copy link
Member

cfbolz commented Nov 10, 2024

In the section "Computing constants and other intermediate results", should not C = C1 + C1 be C = C1 + C2?

absolutely, fix is on the way.

@cfbolz
Copy link
Member

cfbolz commented Nov 10, 2024

it's unclear why you need to add the rule check y.known_ge_const(0) and y.known_le_const(LONG_BIT)

Yeah, that's a good point. I cargo-culted the check y.known_ge_const(0) and y.known_le_const(LONG_BIT) part from the non-dsl version of the code. The metainterp/blackhole consider it undefined to shift by something negative or large and raise an assertion. But I don't model a result being undefined in the Z3 proofs yet, so I'll have to think a bit more carefully about the whole area (also because I would like to move some of the int_add_ovf rules to the DSL). Right now I inherit the semantics of int_lshift from Z3 in the proofs, and that returns 0 if the shift amount is outside of the 0...63 range.

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

No branches or pull requests

4 participants