Skip to content

SVE: Reuse ptrue value instead of rematerializing it everytime #114286

Open

Description

@kunalspathak

Noticed the below piece of code, where we materialize p0 before every usage instead of just saving it and reusing it.

G_M34563_IG04:        ; bbWeight=4, gcrefRegs=0000 {}, byrefRegs=0000 {}, byref, isz
            ldp     q18, q19, [x0]
            ptrue   p0.d
            fabs    z18.d, p0/m, z18.d
            fadd    v0.2d, v0.2d, v18.2d
            ptrue   p0.d
            fabs    z18.d, p0/m, z19.d
            fadd    v0.2d, v0.2d, v18.2d
            ldp     q18, q19, [x0, #0x20]
            ptrue   p0.d
            fabs    z18.d, p0/m, z18.d
            fadd    v0.2d, v0.2d, v18.2d
            ptrue   p0.d
            fabs    z18.d, p0/m, z19.d
            fadd    v0.2d, v0.2d, v18.2d
            ldp     q18, q19, [x0, #0x40]
            ptrue   p0.d
            fabs    z18.d, p0/m, z18.d
            fadd    v0.2d, v0.2d, v18.2d
            ptrue   p0.d
            fabs    z18.d, p0/m, z19.d
            fadd    v0.2d, v0.2d, v18.2d
            ldp     q18, q19, [x0, #0x60]
            ptrue   p0.d
            fabs    z18.d, p0/m, z18.d
            fadd    v0.2d, v0.2d, v18.2d
            ptrue   p0.d
            fabs    z18.d, p0/m, z19.d
            fadd    v0.2d, v0.2d, v18.2d
            add     x0, x0, #128
            sub     x1, x1, #16
            cmp     x1, #16
            bhs     G_M34563_IG04

Either we can track the number of usages (probably count separate groups that do not cross call boundary) and then store them as LclVar. We could have a dedicated predicate register to represent ptrue value, but we would need to have different registers depending on the type (ptrue p0.b and ptrue p0.d are different).

Activity

  1. ghost added
    needs-area-label
    on Apr 4, 2025
  2. kunalspathak commented on Apr 4, 2025

    @kunalspathak
    ContributorAuthor

    @dotnet/arm64-contrib

  3. added
    untriaged
    on Apr 4, 2025
  4. added
    area-CodeGen-coreclr
    arm-sve
    and removed
    untriaged
    on Apr 4, 2025
  5. added this to the 10.0.0 milestone on Apr 4, 2025
  6. self-assigned this
    on Apr 4, 2025
  7. dotnet-policy-service commented on Apr 4, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  8. removed
    needs-area-label
    on Apr 5, 2025
  9. kunalspathak commented on Apr 7, 2025

    @kunalspathak
    ContributorAuthor

    One of the problems is that we introduce bunch of them in lowering and hence VN or CSE cannot do anything about it. Here is one the sample dump:

    1239.dump.asm.zip

  10. kunalspathak commented on Apr 7, 2025

    @kunalspathak
    ContributorAuthor

    One option would be to assign local var with a dedicated lclNum (similar to how it is done in #105348) when we do CreateTrueAllMask(type) during lowering and LSRA should keep the values in register. The lclNum need to be different based on type, and it should kill those lclNum at call boundary to avoid storing and restoring the predicate registers on stack.

  11. modified the milestones: 10.0.0, Future on May 30, 2025
  12. kunalspathak commented on May 30, 2025

    @kunalspathak
    ContributorAuthor

    We won't have time to do it in .NET 10

  13. a74nh commented on Jun 11, 2025

    @a74nh
    Contributor

    #115566 makes all ptrues into CNS_MASK nodes. That should be a large step in the right direction for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrarm-sve

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions