Skip to content

Optimize AdvSimd.Extract() when passed variable that can be const propagated #36070

@kunalspathak

Description

@kunalspathak
public byte DoExtract(Vector64<byte> vector) {
  int index = 5;
  AdvSimd.Extract(vector, index);
}

I was expecting it to generate:

G_M20657_IG02:
        3DC007B0          ldr     q16, [fp,#16]
        0E0B3E00          umov    w0, v16.b[5]

But instead we generate the following.

G_M20657_IG02:
        3DC007A0          ldr     q0, [fp,#16]
        528000A0          mov     w0, #5
        97FFF7F5          bl      System.Runtime.Intrinsics.Arm.AdvSimd:Extract(System.Runtime.Intrinsics.Vector128`1[Byte],ubyte):ubyte
        53001C00          uxtb    w0, w0

It happens because we decide whether to fallback or not depending on the index operand. If it is const, we generate the optimize code however this decision happens during importing and we won't know if the operand is constant or not until we do constant propagation which is in later phase.

We should also investigate if there are more scenarios in which we miss optimizing opportunity because of this dependency and evaluate if we should do the decision after constant propagation is done probably in lower.

category:cq
theme:hardware-intrinsics
skill-level:intermediate
cost:medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:3Work that is nice to havearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions