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 'cond == test->AsOp()->gtOp1' during 'Update flow graph early pass' #103600

Closed
jakobbotsch opened this issue Jun 17, 2024 · 5 comments · Fixed by #103649
Closed
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@jakobbotsch
Copy link
Member

// Generated by Fuzzlyn v1.6 on 2024-06-16 15:10:23
// Run on X64 Windows
// Seed: 6886681321438315426
// Reduced from 30.1 KiB to 0.3 KiB in 00:01:11
// Hits JIT assert in Release:
// Assertion failed 'cond == test->AsOp()->gtOp1' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Update flow graph early pass' (IL size 27; hash 0xade6b36b; FullOpts)
// 
//     File: D:\a\_work\1\s\src\coreclr\jit\fgopt.cpp Line: 5447
// 
using System.Runtime.CompilerServices;

public class Program
{
    public static void Main()
    {
        ulong[] vr0 = default(ulong[]);
        if (0 > vr0[0])
        {
            vr0 = vr0;
        }
        else
        {
            vr0 = new ulong[]{0};
        }

        vr0[0] = vr0[0];
    }
}

cc @amanasifkhalid, looks like there's still some of these cases hanging around.

@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 Jun 17, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jun 17, 2024
Copy link
Contributor

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

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Jun 17, 2024

Actually this looks more like a coincidence. I bisected this to #103382. @tannergooding can you please take a look? There is an invariant in the JIT until lowering that the child node of GT_JTRUE must be a relop, so it is illegal to fold those nodes.

@tannergooding
Copy link
Member

There is an invariant in the JIT until lowering that the child node of GT_JTRUE must be a relop, so it is illegal to fold those nodes.

@jakobbotsch, so basically we can't ever fold relops (GT_LE, GT_GE, GT_LT, GT_GT, GT_EQ, or GT_NE) if one operand is constant and the other has a side effect?

I don't think we have an easy way to check the use here (and may not even have one if the folding is happening in early import), but it seems like this might be missing some optimization opportunities if we can't do this folding since we won't see that the JTRUE is always taken, right?

@jakobbotsch
Copy link
Member Author

There is an invariant in the JIT until lowering that the child node of GT_JTRUE must be a relop, so it is illegal to fold those nodes.

@jakobbotsch, so basically we can't ever fold relops (GT_LE, GT_GE, GT_LT, GT_GT, GT_EQ, or GT_NE) if one operand is constant and the other has a side effect?

There is GTF_RELOP_JMP_USED, though I'm not sure how up to date it is at this point.

I don't think we have an easy way to check the use here (and may not even have one if the folding is happening in early import), but it seems like this might be missing some optimization opportunities if we can't do this folding since we won't see that the JTRUE is always taken, right?

Morph folds these by ensuring the branch is also folded and the flow graph updated. It might be that you can fix the issue here by teaching the morph part to recognize this new result of folding that might be a comma-wrapped constant (it will need to do similar extraction of side effects into a new statement before the JTRUE).

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Jun 17, 2024

Actually it's not morph, but rather import that needs to be taught to recognize this new shape of folded relops.

This needs to be updated to handle the new cases:

/* Fold comparison if we can */
op1 = gtFoldExpr(op1);
/* Try to fold the really simple cases like 'iconst *, ifne/ifeq'*/
/* Don't make any blocks unreachable in import only mode */
if (op1->gtOper == GT_CNS_INT)

@EgorBo EgorBo removed the untriaged New issue has not been triaged by the area owner label Jun 18, 2024
@EgorBo EgorBo added this to the 9.0.0 milestone Jun 18, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 20, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants