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

[ARM64/Linux] Inefficiencies when using initializing/cleaning unsafe pointers #12736

Closed
Tracked by #77010
TamarChristinaArm opened this issue May 22, 2019 · 6 comments
Closed
Tracked by #77010
Labels
arch-arm64 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI JitUntriaged CLR JIT issues needing additional triage
Milestone

Comments

@TamarChristinaArm
Copy link
Contributor

For the following case with QuickJIT turned off

static int[] Test(int[] a)
{
  unsafe {
    fixed (int *a_ptr = a, b_ptr = b)
    {
    }
  }
  return a;
}

The initialization of the pointer correctly uses the zero register

        F9000FBF          str     xzr, [fp,#24] // [V05 loc2]
        F9000BBF          str     xzr, [fp,#16] // [V06 loc3]

However it doesn't use stp/ldp when it's possible to.

also when cleaning up the strs suddenly don't use xzr anymore

        D2800001          mov     x1, #0
        F9000FA1          str     x1, [fp,#24]  // [V05 loc2]
        F9000BA1          str     x1, [fp,#16]  // [V06 loc3]

/CC @CarolEidt @tannergooding

category:cq
theme:basic-cq
skill-level:intermediate
cost:medium

@mikedn
Copy link
Contributor

mikedn commented May 22, 2019

also when cleaning up the strs suddenly don't use xzr anymore

It looks like the code in lowerarmarch.cpp's Lowering::ContainCheckStoreLoc was copied from xarch/arm32 without proper adjustment for arm64:

// If the source is a containable immediate, make it contained, unless it is
// an int-size or larger store of zero to memory, because we can generate smaller code
// by zeroing a register and then storing it.

Obviously, arm64 doesn't need to zero a register. Properluy checking for 0 should fix this.

However it doesn't use stp/ldp when it's possible to.

Unfortunately the JIT doesn't have any support for something like this. Perhaps it could be done in codegen, by looking ahead at the IR. Otherwise it would be problematic to encode a stp-like operation in JIT's IR at an earlier stage.

@AndyAyersMS
Copy link
Member

Might want to consider fixing the zero reg issue for 3.0, but will mark as future.

@CarolEidt
Copy link
Contributor

Might want to consider fixing the zero reg issue for 3.0, but will mark as future.

Right - the zero reg issue should be pretty straightforward to fix, but as @mikedn indicates, the allocation and code generation for register pairs is somewhat more complex (though, thankfully, should be easier than the arm32 doubles!)

@BruceForstall BruceForstall changed the title [ARM64/Linux] Ineffincies when using initializing/cleaning unsafe pointers [ARM64/Linux] Inefficiencies when using initializing/cleaning unsafe pointers Sep 22, 2019
@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@BruceForstall BruceForstall added the JitUntriaged CLR JIT issues needing additional triage label Oct 28, 2020
@SwapnilGaikwad
Copy link
Contributor

The zero reg issue is already fixed by the PR #52269.

Assembly with and without the above patch is following.
Without patch:

mov     x0, xzr
str     x0, [fp, #0x38]	// [V04 loc2]
mov     x0, xzr
str     x0, [fp, #0x30]	// [V05 loc3]

With patch:

str     xzr, [fp, #0x38]	// [V04 loc2]
str     xzr, [fp, #0x30]	// [V05 loc3]

Regarding ldp/stp usage, there are other issues (for ldp: #35132, #35130; stp: #35133, #35134) tracking it.

@a74nh
Copy link
Contributor

a74nh commented Oct 26, 2022

@kunalspathak

@kunalspathak
Copy link
Member

Thanks for checking @SwapnilGaikwad .

@ghost ghost locked as resolved and limited conversation to collaborators Nov 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-arm64 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI JitUntriaged CLR JIT issues needing additional triage
Projects
None yet
Development

No branches or pull requests

9 participants