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

feat[next]: Extend and refactor constant folding #1810

Open
wants to merge 56 commits into
base: main
Choose a base branch
from

Conversation

SF-N
Copy link
Contributor

@SF-N SF-N commented Jan 21, 2025

The following new transformations are introduced:

  • CANONICALIZE_OP_FUNCALL_SYMREF_LITERAL:
    literal, symref -> symref, literal, prerequisite for FOLD_FUNCALL_LITERAL, FOLD_NEUTRAL_OP
    literal, funcall -> funcall, literal, prerequisite for FOLD_FUNCALL_LITERAL, FOLD_NEUTRAL_OP
    funcall, op -> op, funcall for s[0] + (s[0] + 1), prerequisite for FOLD_MIN_MAX_PLUS
  • CANONICALIZE_MINUS: a - b -> a + (-b), prerequisite for FOLD_MIN_MAX_PLUS
  • CANONICALIZE_MIN_MAX: maximum(a, maximum(...)) -> maximum(maximum(...), a), prerequisite for
  • FOLD_FUNCALL_LITERAL: (a + 1) + 1 -> a + (1 + 1)
  • FOLD_MIN_MAX:
    maximum(maximum(a, 1), a) -> maximum(a, 1)
    maximum(maximum(a, 1), 1) -> maximum(a, 1)
  • FOLD_MIN_MAX_PLUS: maximum(plus(a, 1), a) -> plus(a, 1)
    maximum(plus(a, 1), plus(a, -1)) -> plus(a, maximum(1, -1))
  • FOLD_NEUTRAL_OP: a + 0 -> a, a * 1 -> a

In the end, unary minuses are transformed back to minus-calls where possible by UndoCanonicalizeMinus:
a + (-b) -> a - b , -a + b -> b - a, -a + (-b) -> -a - b

In addition the pass now transforms until a fixed point is reached (like in the CollapseTuple pass) instead of just transforming once. The FixedPointTransformation class from PR 1826 is used here.

Previously, large nested maximum expressions like maximum(maximum(maximum(maximum(sym, 1),...), 1), maximum(maximum(sym, 1), 1)) caused timeouts in PMAP-GO as the runtime of the domain inference increased significantly due to the large domain expressions that could not be simplified.

This replaces this PR.

@SF-N SF-N requested a review from tehrengruber February 11, 2025 13:57
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