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

PIL OPT: optimize ((x + 1) + 3) to (x + 4) #2413

Open
chriseth opened this issue Jan 30, 2025 · 0 comments · May be fixed by #2419
Open

PIL OPT: optimize ((x + 1) + 3) to (x + 4) #2413

chriseth opened this issue Jan 30, 2025 · 0 comments · May be fixed by #2419

Comments

@chriseth
Copy link
Member

The pil optimizer can evaluated operations on literals like 1 + 3 -> 4, but it cannot make use of associativity and commutativity. So it does not optimize x + 1 + 3 to x + 4, because it is parsed as (x + 1) + 3.

We should implement the following rules (Li is a literal, X is any expression) - in post-visit-order:

  • (X + L1) + L2 -> X + (L1 + L2)
  • (L1 + X) + L2 -> X + (L1 + L2)
  • (L1 + X) + Y -> (X + Y) + L1 (this is needed to simplify e.g. ((X + 3) + Y) + 9)
  • (X + L1) + Y -> (X + Y) + L1
  • ...
@gzanitti gzanitti linked a pull request Jan 30, 2025 that will close this issue
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 a pull request may close this issue.

1 participant