Skip to content

Arm64 SVE: Fix conditionalselect with constant arguments #116852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

a74nh
Copy link
Contributor

@a74nh a74nh commented Jun 20, 2025

Fixes #116847

When folding, allow arg1 to be a constant mask

Fixes dotnet#116847

When folding, allow arg1 to be a constant mask
@a74nh a74nh marked this pull request as ready for review June 20, 2025 10:46
@a74nh
Copy link
Contributor Author

a74nh commented Jun 20, 2025

@dotnet/arm64-contrib @kunalspathak

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 20, 2025
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 20, 2025
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@kunalspathak
Copy link
Member

/azp run Antigen, Fuzzlyn

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

// depending on if the corresponding input element
// has its least significant bit set

bool isSet = static_cast<uint64_t>(1) << (i * sizeof(TBase));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, we should be check isSet with content of input0, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, we should be check isSet with content of input0, right?

Yes, I should be checking significant bit of input0

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bug in EvaluateSimdVectorToPattern where we are not validating it against the contents of arg0.

@a74nh
Copy link
Contributor Author

a74nh commented Jun 23, 2025

The simd.h changes in this PR are out of date. We should wait for #116854 to be merged first.

@kunalspathak
Copy link
Member

i will hold off reviewing this until #116854 is merged.

@a74nh
Copy link
Contributor Author

a74nh commented Jun 24, 2025

Fuzzlyn was showing some errors with

Assert failure(PID 1845356 [0x001c286c], Thread: 1845356 [0x1c286c]): Assertion failed 'OperIs(GT_CNS_VEC)' in 'Program:M1(byref,int,System.Runtime.Intrinsics.Vector64`1[ushort]):ushort' during 'Morph - Global' (IL size 56; hash 0xc2f1cf02; FullOpts)

    File: /mnt/sdb/home/alahay01/dotnet/runtime_madv/src/coreclr/jit/gtstructs.h:64
    Image: /mnt/sdb/home/alahay01/dotnet/runtime_madv/artifacts/tests/coreclr/linux.arm64.Checked/Tests/Core_Root/corerun

This is due to EvalHWIntrinsicFunTernary() not treating arg1 of NI_Sve_ConditionalSelect` as a mask.

The fix is closely related to the fix in this PR, so I've put it into this PR with a test.

I've also updated simd.h to the latest from #116854

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@a74nh
Copy link
Contributor Author

a74nh commented Jun 27, 2025

I've put another closely related Fuzzlyn failure into this PR.

Assert failure(PID 3199223 [0x0030d0f7], Thread: 3199223 [0x30d0f7]): Assertion failed 'unreached' in 'ConditionalSelectConstants:ConditionalSelectConstsNoMaskPattern():bool' during 'Generate code' (IL size 74; hash 0xca97730c; FullOpts)

    File: /mnt/sdb/home/alahay01/dotnet/runtime_sve/src/coreclr/jit/codegenarm64.cpp:2379
    Image: /mnt/sdb/home/alahay01/dotnet/runtime_sve/artifacts/tests/coreclr/linux.arm64.Checked/Tests/Core_Root/corerun

What happens here is all the inputs to the conditionalselect are constants, so it is optimised away into a single vector. It is then used as a mask in the next function call, so is optimised to a cns mask. The mask cannot be converted into a valid pattern during codegen (for use in a ptrue), so it asserts. The fix is to convert it to a constant vector with conversion to mask. Best way to do that is during lowering (see LowerCnsMask()), this ensures we have the registers etc required for the conversion.

a74nh added 3 commits June 27, 2025 10:17
Change-Id: I7951b70aec9aaef5521e100d30737b5a4d332b38
@a74nh
Copy link
Contributor Author

a74nh commented Jun 27, 2025

With #116991 applied on top I don't see any fuzzlyn errors over 50mins. I'm happy with this PR now.

@a74nh
Copy link
Contributor Author

a74nh commented Jun 30, 2025

Updated as per review comments. Fuzzlyn still looks good when #116991 is applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Arm64 SVE: Error when ConditionalSelect has all constant arguments
3 participants