Skip to content
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

JIT: Assertion failed '(imm < maxVal) || ((imm & signBitsMask) == signBitsMask)' during 'Generate code' #106020

Closed
jakobbotsch opened this issue Aug 6, 2024 · 2 comments · Fixed by #106092
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@jakobbotsch
Copy link
Member

// Generated by Fuzzlyn v2.2 on 2024-08-05 19:14:52
// Run on Arm64 MacOS
// Seed: 16897731911671998240-vectort,vector64,vector128,armadvsimd,armadvsimdarm64,armaes,armarmbase,armarmbasearm64,armcrc32,armcrc32arm64,armdp,armrdm,armrdmarm64,armsha1,armsha256
// Reduced from 67.3 KiB to 0.3 KiB in 00:00:23
// Hits JIT assert in Debug:
// Assertion failed '(imm < maxVal) || ((imm & signBitsMask) == signBitsMask)' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Generate code' (IL size 16; hash 0xade6b36b; MinOpts)
// 
//     File: /Users/runner/work/1/s/src/coreclr/jit/emitarm64.cpp Line: 2676
// 
using System;
using System.Runtime.CompilerServices;
using System.Numerics;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;

public class Program
{
    public static void Main()
    {
        int vr2 = 0;
        Vector128.Create<short>((short)((0 * vr2) + 2147483647));
    }
}

cc @dotnet/jit-contrib

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Aug 6, 2024
@jakobbotsch jakobbotsch added this to the 9.0.0 milestone Aug 6, 2024
@jakobbotsch jakobbotsch removed the untriaged New issue has not been triaged by the area owner label Aug 6, 2024
@JulieLeeMSFT
Copy link
Member

@amanasifkhalid, PTAL.

@amanasifkhalid
Copy link
Member

amanasifkhalid commented Aug 7, 2024

In MinOpts, we don't constant-fold casts, so before rationalizing, we have the following IR for the intrinsic:

*  STORE_LCL_VAR simd16 V02 tmp1
\--*  HWINTRINSIC simd16 short Create
   \--*  CAST      int <- short <- int
      \--*  CNS_INT   int    0x7FFFFFFF

Then during lowering, we lower the intrinsic to DuplicateToVector128, and then try to replace the GT_CAST operand with a constant in Lowering::IsValidConstForMovImm -- this seems like a last-minute effort to make up for the fact that we don't constant-fold in MinOpts. But unlike the folding logic for casts, this path doesn't modify the immediate if it's being casted to a smaller type, which seems illegal. Without asserts, emitter::normalizeImm64 will chop off the overflowing bits, but the failing assert suggests normalizeImm64 should only encounter overly-large immediates at this point if the sign bit has been extended; it doesn't take responsibility for casting immediates to smaller sizes.

We could duplicate the logic from constant-folding to fix the immediate, but since this path seems to only be relevant in MinOpts, I don't think we would gain much. I think the most surgical fix is to block the cast removal if we're narrowing the type, since narrowing casts might affect the immediate.

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Aug 7, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants