Skip to content

ARM64: Virtual stub call produces redundant address load for R2R and JIT #36700

Closed
@kunalspathak

Description

@kunalspathak

While working on #35675, I noticed that there are scenarios when we do virtual stub call, we generate redundant code to load the stub address. This is true in R2R as well as JIT.

public class B : I
{
    int I.F() => 33;
}

public class D : B, I
{
    int I.F() => 44;
}

public class E : B, I
{
    int I.F() => 55;
}

public long Call(TestInput testInput)
{
  long sum = 0;
  for (int i = 0; i < input.Length; i++)
  {
    sum += ((I)input[i]).F();
   }
  return sum;
}

For this code, we still generate duplicate adrp/add pair and can be optimized similar to done in #35675.

        9000000B          adrp    x11, [RELOC #0x231e87739b0]
        9100016B          add     x11, x11, #0
        90000001          adrp    x1, [RELOC #0x231e87739b0]
        91000021          add     x1, x1, #0
        F9400021          ldr     x1, [x1]
        D63F0020          blr     x1

Here is the JIT code that we generate today:

        D2800A0B          movz    x11, #80
        F2BB538B          movk    x11, #0xda9c LSL #16
        F2CFFF6B          movk    x11, #0x7ffb LSL #32
        D2800A01          movz    x1, #80
        F2BB5381          movk    x1, #0xda9c LSL #16
        F2CFFF61          movk    x1, #0x7ffb LSL #32
        F9400021          ldr     x1, [x1]
        D63F0020          blr     x1
        93407C00          sxtw    x0, w0
        8B140014          add     x20, x0, x20
        110006F7          add     w23, w23, #1
        6B17031F          cmp     w24, w23
        54FFFE0C          bgt     G_M49262_IG04
                                                ;; bbWeight=16    PerfScore 240.00
G_M49262_IG05:
        110006B5          add     w21, w21, #1
        5290D400          movz    w0, #0x86a0

Similar issue but for different scenario: #35108

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions