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

Add new simplification rule for invariant loop parameters. #1990

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Aug 3, 2023

  1. Add new simplification rule for invariant loop parameters.

    This was suggested by Cosmin to address some of the code produced by
    AD.
    
    The idea is that for a loop of the form
    
    loop p = x ...
      ...stms...
      in res
    
    we construct and simplify the body
    
      let p = x
      ...stms...
      in res
    
    and if that simplifies to 'x', then we conclude that the loop
    parameter 'p' must be invariant to the loop and simply bind it (and
    the loop result) to 'x'.
    
    Complication: for multi-parameter loops, we must also check that
    the *original* computation of 'res' does *only* depends on other
    invariant loop parameters.
    
    Currently we do this only for loops that have a constant as one of
    their initial loop parameter values.
    
    The main downside of this rule is that doing recursive simplification
    is quite expensive.  Especially after sequentialisation, pretty much
    every 'reduce' will have been turned into a loop that triggers this
    rule (although the rule itself will fail in most cases, after doing
    the simplification).  Therefore I'm a bit hesitant to enable it as is.
    Sure, the Futhark compiler is slow and it was never meant to be fast,
    but it is still quite easy for the compiler to become *uselessly slow*
    if we are not careful.  E.g. on OptionPricing, this rule itself makes
    compilation 10% slower (and does not actually optimise anything - this
    is purely the cost of failing checks).
    athas committed Aug 3, 2023
    Configuration menu
    Copy the full SHA
    3127997 View commit details
    Browse the repository at this point in the history