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

riscv64: Refactor and enable optimizing sign extensions #7121

Merged
merged 16 commits into from
Oct 2, 2023

Commits on Oct 1, 2023

  1. Configuration menu
    Copy the full SHA
    47851bb View commit details
    Browse the repository at this point in the history
  2. riscv64: Refactor int-to-float emission

    Use ISLE matching to generate different instructions rather than having
    a method deeper in the backend select which instruction to use.
    Additionally remove the usage of the `normalize_fcvt_to_int` helper.
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    08de074 View commit details
    Browse the repository at this point in the history
  3. riscv64: Refactor and simplify lower_bmask

    Take a `Value` as input to simplify 128-bit handling and additionally
    simplify the rules a bit with other helpers.
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    407c403 View commit details
    Browse the repository at this point in the history
  4. riscv64: Refactor normalize_cmp_value and truthy_to_reg

    Remove the normalization completely by folding it into callers and
    refactor `truthy_to_reg` to perform sign extension internally in
    addition to handling 128-vs-64
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    35b17cc View commit details
    Browse the repository at this point in the history
  5. riscv64: Remove 128-bit handling from extension helper

    This is only needed in a small handful of spots which can pretty easily
    handle the sign extension on their own, and this further simplifies sign
    extension to purely dealing with a single register.
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    8ea8dea View commit details
    Browse the repository at this point in the history
  6. riscv64: Remove destination type in extension

    This is always `$I64`, so no need to pass it around.
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    b77e4b9 View commit details
    Browse the repository at this point in the history
  7. riscv64: Remove ext_if_need helper

    Fold 128-bit handling into callers as necessary
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    eb2867f View commit details
    Browse the repository at this point in the history
  8. riscv64: Refactor sext to take a Value

    This commit refactors the `sext` helper to take a single `Value` as an
    argument rather than an `XReg Type` combo. This will enable, in future
    commits, to pattern-match the structure of the input and skip the sign
    extension if possible. For example an `icmp` result is already
    sign-extended.
    
    This involved moving some `lower_*` declarations directly into
    `lower.isle`. Additionally a special-case of lowering `brif` was removed
    which caused regressions in generated code due to new `and` instructions
    being generated to sign-extend the result of an `icmp`. Once `zext` is
    also migrated to this pattern this regression should be fixed, so this
    should just be a temporary state of affairs.
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    53ee6e6 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    1014819 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    9fb9fb3 View commit details
    Browse the repository at this point in the history
  11. riscv64: Fold lower_popcnt into lower.isle

    This slightly pessmizes codegen when the `zbb` extension isn't available
    due to a sign extension for smaller-than-64-bit types, but this is
    possible to fix in the future if necessary and helps simplify this in
    the meantime.
    
    Additionally this lifts the special cases for `has_zbb` directly into
    the lowering rule.
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    b653187 View commit details
    Browse the repository at this point in the history
  12. riscv64: Refactor clz and cls

    This commit refactors the lowering rules for these two CLIF instructions
    to move the sext/zext operations to the top rather than having them
    buried in lowering rules. This additionally moves them to `lower.isle`
    instead of `inst.isle`. This did result in some minor duplication but
    overall feels a bit better due to them being less coupled now.
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    ce1b218 View commit details
    Browse the repository at this point in the history
  13. riscv64: Move gen_bswap to lower.isle

    Additionally shuffle rules around to remove the dependence on `zext`
    because when this zero-extension happens it's known that many of the
    extension-related optimizations are not applicable. This does pessimize
    code slightly but it's hopefully not too bad given the current size of
    the bswap lowering.
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    a59fa73 View commit details
    Browse the repository at this point in the history
  14. riscv64: Change zext to taking a Value

    This is similar to a prior commit for `sext` and will enable future
    optimizations to skip the zext entirely if the structure of the value
    allows.
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    bd89420 View commit details
    Browse the repository at this point in the history
  15. riscv64: Fold extend helper into zext and sext

    This commit folds the existing rules of the `extend` helper into the
    corresponding functions of `zext` and `sext`. They are the only callers
    of `extend` and this keeps the sign extension-related logic truly in one
    final resting place now at this point. A new matcher
    `val_already_extended` is additionally added to add more cases in a
    follow-up commit to enable skipping sign-extension operations based on
    the structure of the `Value` input.
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    59969b2 View commit details
    Browse the repository at this point in the history
  16. riscv64: Optimize some sign extensions

    As the culmination of all prior commits, this commit adds a few cases
    where a sign extension is not necessary in the backend and can be
    skipped. For example extending a sign-extended value is not required
    because the backend always extends to the full register width.
    Additionally extending the result of an `icmp` is not necessary since
    that always produces a 0 or 1 value at the full register width.
    alexcrichton committed Oct 1, 2023
    Configuration menu
    Copy the full SHA
    4378947 View commit details
    Browse the repository at this point in the history