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

Remove mono specific SpanHelpers #78015

Closed
wants to merge 12 commits into from

Commits on Nov 18, 2022

  1. Configuration menu
    Copy the full SHA
    d946c3b View commit details
    Browse the repository at this point in the history
  2. [System.Span] Optimize hot loops by simplifying offset computation

    Before, for every single element, the address `address + offset + ct` had to be computed. In theory, a smart compiler would be able to reuse `address + offset` value and offset it only by a constant to obtain every single element. Do this explicitly to avoid reliance on advanced optimizations.
    BrzVlad committed Nov 18, 2022
    Configuration menu
    Copy the full SHA
    3b73bb5 View commit details
    Browse the repository at this point in the history
  3. [System.Span] Refactor hot loop code

    This would replace code like
    
    ```
    load
    b.neq
      add
      ret
    load
    b.neq
      add
      ret
    load
    ....
    ```
    with
    
    ```
    load
    b.eq
    load
    b.eq
    load
    ...
    ```
    
    This makes the code more compact in the hot loop, reduces overall code size and thus improves performance. This pattern is widely used and it was also used before with Span lookups.
    BrzVlad committed Nov 18, 2022
    Configuration menu
    Copy the full SHA
    a48fb6f View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    fe06a72 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    ff36071 View commit details
    Browse the repository at this point in the history
  6. [mono][interp] Improve detection of dead bblocks

    Before we were marking bblocks as dead if they had their in_count 0. This is not enough however, since it doesn't account for loops. We now do a full traversal of the bblock graph to detect unreachable bblocks.
    BrzVlad committed Nov 18, 2022
    Configuration menu
    Copy the full SHA
    fb2bcde View commit details
    Browse the repository at this point in the history
  7. [mono][interp] Reorder bblocks to facilitate propagation of values

    Consider for example the following pattern used commonly with conditional branches:
    ```
         br.s           [nil <- nil], BB0
         ...
         ceq0.i4        [32 <- 40],
         br.s           [nil <- nil], BB1
    
    BB0: ldc.i4.0       [32 <- nil],
    BB1: brfalse.i4.s   [nil <- 32], BB_EXIT
    
    BB2: ldstr          [56 <- nil], 2
    
    ```
    This commit reorders this code to look like:
    ```
         br.s           [nil <- nil], BB0
         ...
         ceq0.i4        [32 <- 40],
         brfalse.i4.s   [nil <- 32], BB_EXIT
         br.s           [nil <- nil], BB2
    
    BB0  ldc.i4.0       [32 <- nil],
    BB1: brfalse.i4.s   [nil <- 32], BB_EXIT
    
    BB2: ldstr          [56 <- nil], 2
    
    ```
    
    This means we will have duplicated brfalse instructions, but every basic block reaching the conditional branch will have information about the condition. For example ceq0.i4 + brfalse is equivalent to brtrue, ldc.i4.0 + brfalse is equivalent to unconditional branch. After other future optimizations applied on the bblocks graph, like removal, merging and propagation of target, the resulting code in this example would look like:
    ```
         br.s           [nil <- nil], BB_EXIT
         ...
         brtrue.i4.s    [nil <- 40], BB_EXIT
    BB2: ldstr          [56 <- nil], 2
    
    ```
    Which is a great simplification over the original code.
    BrzVlad committed Nov 18, 2022
    Configuration menu
    Copy the full SHA
    5379908 View commit details
    Browse the repository at this point in the history
  8. [mono][interp] Don't optimize out bblocks that are tiering patchpoint…

    … targets
    
    Even though they can be become unreachable in the current method, they can still be called when the unoptimized method gets tiered at this point.
    
    Add assert to prevent such issues in the future.
    BrzVlad committed Nov 18, 2022
    Configuration menu
    Copy the full SHA
    c8edcde View commit details
    Browse the repository at this point in the history
  9. [mono][interp] Make bblock reordering more conservative

    If we are unlikely to gain anything from propagating the condition (if we don't have information about any of the condition operand vars), simply avoid the optimization.
    BrzVlad committed Nov 18, 2022
    Configuration menu
    Copy the full SHA
    cffdc02 View commit details
    Browse the repository at this point in the history
  10. [mono][interp] Add basic removal of unused defines

    If we store in a var and this var is not used and redefined by the end of the basic block, then we can clear the original store.
    BrzVlad committed Nov 18, 2022
    Configuration menu
    Copy the full SHA
    5e8571f View commit details
    Browse the repository at this point in the history
  11. [mono][interp] Clear unused defines of local only vars

    We detect if a var's value never escapes the definition of a bblock. We mark such vars and clear unused definitions of that var from other bblocks.
    BrzVlad committed Nov 18, 2022
    Configuration menu
    Copy the full SHA
    e4abb67 View commit details
    Browse the repository at this point in the history
  12. [mono][interp] Propagate target branches

    If a bblock contains only an unconditional br, then all bblocks branching into it can just call the target directly instead.
    BrzVlad committed Nov 18, 2022
    Configuration menu
    Copy the full SHA
    954483a View commit details
    Browse the repository at this point in the history