Skip to content

Some hardware intrinsic nodes can reorder side effects #54956

Closed

Description

@SingleAccretion

Reproduction:

using System.Numerics;
using System.Runtime.CompilerServices;

SideEffects(null, new Vector<int>[] { });

[MethodImpl(MethodImplOptions.NoInlining)]
static Vector<int> SideEffects(Vector<int>* a, Vector<int>[] b)
{
    var v = Vector.AndNot(*a, b[0]);

    return v;
}

Actual result:

> dotnet run
Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.

Expected result:

> dotnet run
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.

This happens because of this code:

if (SimdAsHWIntrinsicInfo::NeedsOperandsSwapped(intrinsic))
{
std::swap(op1, op2);
}

Which does not account for side effects. Important note: since the importation code does not propagate the side effect flags properly (yet), they cannot be relied on when determining whether it is safe to swap at that point.

Possible solutions:

  1. Aggressively spill to temps - bad from CQ & TP standpoints.
  2. Use GTF_REVERSE_OPS - bad from the standpoint that this flag should be removed.
  3. Fix the operands up in LIR, where the tree walk no longer determines the execution order - probably cleanest but also most complex solution.

Note: the problematic code will become less centralized after #53450 is merged. See my review notes over there.

Activity

  1. ghost added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Jun 30, 2021
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Jun 30, 2021
  3. removed
    untriagedNew issue has not been triaged by the area owner
    on Jul 6, 2021
  4. added this to the Future milestone on Jul 6, 2021
  5. modified the milestones: Future, 7.0.0 on Oct 14, 2021
  6. echesakov commented on Mar 15, 2022

    @echesakov
    Contributor

    Un-assigning myself
    cc @BruceForstall

  7. removed their assignment
    on Mar 15, 2022
  8. AndyAyersMS commented on Apr 28, 2022

    @AndyAyersMS
    Member

    Seems like we ought to fix this and should assign somebody.

  9. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on May 31, 2022
  10. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 7, 2022
  11. ghost locked as resolved and limited conversation to collaborators on Aug 6, 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 havearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIbug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions