Skip to content
  • Andreas Klebinger's avatar
    cmm: Use two equality checks for two alt switch with default · 7ff60235
    Andreas Klebinger authored
    For code like:
    f 1 = e1
    f 7 = e2
    f _ = e3
    
    We can treat it as a sparse jump table, check if we are outside of the
    range in one direction first and then start checking the values.
    
    GHC currently does this by checking for x>7, then x <= 7 and at last x
    == 1.
    
    This patch changes this such that we only compare for equality against
    the two values and jump to the default if non are equal.
    
    The resulting code is both faster and smaller.
    wheel-sieve1 improves by 4-8% depending on problem size.
    
    This implements the idea from #14644
    
    Reviewers: bgamari, simonmar, simonpj, nomeata
    
    Reviewed By: simonpj, nomeata
    
    Subscribers: nomeata, simonpj, rwbarton, thomie, carter
    
    Differential Revision: https://phabricator.haskell.org/D4294
    7ff60235