Skip to content

Use cmeq, cmge, cmgt (zero) when one of the operands is Vector64/128<T>.Zero #33972

Description

@echesakov

For example,

The code as in #33749 (comment) BitArray:.ctor

dup     v17.16b, wzr
cmeq    v16.16b, v16.16b, v17.16b

should be optimized down to

cmeq    v16.16b, v16.16b, #0

This applies to all the intrinsics that are mapped to cmeq, cmge, cmgt, cmle, cmlt, fcmeq, fcmge, fcmgt, fcmle and fcmlt instructions

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

Activity

  1. Gnbrkm41 commented on Mar 31, 2020

    @Gnbrkm41
    Contributor

    // JIT does not support code hoisting for SIMD yet
    // However comparison against zero can be replaced to cmeq against zero (vceqzq_s8)
    // See dotnet/runtime#33972 for details
    Vector128<byte> zero = Vector128<byte>.Zero;
    fixed (bool* ptr = values)
    {
    for (; (i + Vector128ByteCount * 2u) <= (uint)values.Length; i += Vector128ByteCount * 2u)
    {
    // Same logic as SSE2 path, however we lack MoveMask (equivalent) instruction
    // As a workaround, mask out the relevant bit after comparison
    // and combine by ORing all of them together (In this case, adding all of them does the same thing)
    Vector128<byte> lowerVector = AdvSimd.LoadVector128((byte*)ptr + i);
    Vector128<byte> lowerIsFalse = AdvSimd.CompareEqual(lowerVector, zero);

  2. added this to the Future milestone on Apr 4, 2020
  3. removed
    untriagedNew issue has not been triaged by the area owner
    on Apr 4, 2020
  4. modified the milestones: Future, 6.0.0 on Oct 13, 2020
  5. added
    needs-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration
    on Mar 23, 2021
  6. removed
    needs-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration
    on Jun 7, 2021
  7. modified the milestones: 6.0.0, Future on Jul 7, 2021
  8. modified the milestones: Future, 7.0.0 on Oct 15, 2021
  9. echesakov commented on Mar 15, 2022

    @echesakov
    ContributorAuthor

    I believe this item was addressed fully.
    @TIHan can you please confirm and close the issue?

  10. removed their assignment
    on Mar 15, 2022
  11. TIHan commented on Mar 15, 2022

    @TIHan
    Contributor

    Yes, I believe it was. There is more opportunity with other instructions like 'cmle' and 'cmlt', but based on the title of this issue, we got them covered.

  12. ghost locked as resolved and limited conversation to collaborators on Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions