Skip to content

ARM64: redundant store/load in generated constructor code #123078

@DavidWBrooks

Description

@DavidWBrooks

Description

In an admittedly small sample, every constructor generates code like this (clipped from Visual Studio but windbg shows the same code). This is from App.xaml.cs in a starter app using the VS2022 WinUI template, which is an easy repro.

_window = new MainWindow();
00007FFA2CE9C0BC mov x0,#0x48F0
00007FFA2CE9C0C0 movk x0,#0x2DA7,lsl #0x10
00007FFA2CE9C0C4 movk x0,#0x7FFA,lsl #0x20
00007FFA2CE9C0C8 bl CLRStub[JumpStub]@00007FFA2CE60128 (07FFA2CE60128h)
00007FFA2CE9C0CC stur x0,[fp,#-0x18]
00007FFA2CE9C0D0 ldur x0,[fp,#-0x18]
00007FFA2CE9C0D4 bl WinUI.MainWindow..ctor() (07FFA2DA68F48h)

Similar code can be found in WPF, Forms, and a Console app - except Console uses str/ldr, and so does WinUI if I add other constructors. I'm new to ARM64, but I don't see a difference between stur and str for a 64-bit register.

Just to pile on, if the new() is the first parameter to a function call that immediately follows, even the stur is superfluous (although I realize that may not be a peephole optimization).

This is similar to the redundant code found by @kunalspathak over various iterations, but he didn't list this one. And I'd understand if it doesn't happen frequently enough to optimize.

I can see that the stur "belongs" to the previous instruction, and the ldur to the following one, which is why this is probably a peephole fix.

Configuration

Windows 11 build 26200.7462
.NET 9.0.11
ARM64
Visual Studio 2022 Community

Regression?

Not known. The same happens in .NET 8, at any rate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:2Work that is important, but not critical for the releasearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsiderationtenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions