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

Have COND_JUMP handling check for gtEffectiveVal #103649

Merged
merged 5 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7373,15 +7373,17 @@ void Compiler::impImportBlockCode(BasicBlock* block)
// fall through

COND_JUMP:

{
/* 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)
GenTree* effectiveOp1 = op1->gtEffectiveVal();

if (effectiveOp1->OperIs(GT_CNS_INT))
{
/* gtFoldExpr() should prevent this as we don't want to make any blocks
unreachable under compDbgCode */
Expand All @@ -7393,7 +7395,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)

if (block->KindIs(BBJ_COND))
{
bool const isCondTrue = op1->AsIntCon()->gtIconVal != 0;
bool const isCondTrue = effectiveOp1->AsIntCon()->gtIconVal != 0;
FlowEdge* const removedEdge = isCondTrue ? block->GetFalseEdge() : block->GetTrueEdge();
FlowEdge* const retainedEdge = isCondTrue ? block->GetTrueEdge() : block->GetFalseEdge();

Expand Down Expand Up @@ -7463,6 +7465,12 @@ void Compiler::impImportBlockCode(BasicBlock* block)
}
}

if (!op1->OperIs(GT_CNS_INT))
{
// Ensure we spill any side effects and don't drop them
op1 = gtUnusedValNode(op1);
goto SPILL_APPEND;
}
break;
}

Expand All @@ -7477,6 +7485,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)
}

goto SPILL_APPEND;
}

case CEE_CEQ:
oper = GT_EQ;
Expand Down
52 changes: 52 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_103600/Runtime_103600.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using Xunit;

// 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
//
public class Runtime_103600
{
[Fact]
public static int TestEntryPoint()
{
int result = 0;

try
{
Test();
}
catch (NullReferenceException)
{
result = 100;
}

return result;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Test()
{
ulong[] vr0 = default(ulong[]);

if (0 > vr0[0])
{
vr0 = vr0;
}
else
{
vr0 = new ulong[]{0};
}

vr0[0] = vr0[0];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
Loading