Skip to content

Commit

Permalink
Don't fold relops with side effects that are used in jumps (dotnet#10…
Browse files Browse the repository at this point in the history
…3903)

* Don't fold relops with side effects that are used in jumps

* Reorder comparisons
  • Loading branch information
tannergooding authored Jun 24, 2024
1 parent b79c57e commit e6a0fd6
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14299,6 +14299,14 @@ GenTree* Compiler::gtFoldExprSpecial(GenTree* tree)
// Here `op` is the non-constant operand, `cons` is the constant operand
// and `val` is the constant value.

if (((op->gtFlags & GTF_SIDE_EFFECT) != 0) && tree->OperIsCompare() && ((tree->gtFlags & GTF_RELOP_JMP_USED) != 0))
{
// TODO-CQ: Some phases currently have an invariant that JTRUE(x)
// must have x be a relational operator. As such, we cannot currently
// fold such cases and need to preserve the tree as is.
return tree;
}

switch (oper)
{
case GT_LE:
Expand Down
59 changes: 59 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_103888/Runtime_103888.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;
using Xunit;

public class Runtime_103888_A
{
// Generated by Fuzzlyn v1.6 on 2024-06-23 16:50:17
// Run on X64 Windows
// Seed: 14337630088129483600
// Reduced from 13.5 KiB to 0.3 KiB in 00:01:04
// Hits JIT assert in Release:
// Assertion failed 'block->bbPreorderNum == preorderNum' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Early Value Propagation' (IL size 47; hash 0xade6b36b; FullOpts)
//
// File: D:\a\_work\1\s\src\coreclr\jit\fgdiagnostic.cpp Line: 4750
//

public class C0
{
public uint F0;
public int F1;
}

[Fact]
public static void TestEntryPoint()
{
C0 vr0 = new C0();
if (!((ulong)(0 << vr0.F1) <= vr0.F0))
{
vr0.F1 ^= vr0.F1;
}
}
}

public class Runtime_103888_B
{
public static ushort[, ] s_69 = new ushort[1,1];

[Fact]
public static void TestEntryPoint()
{
try
{
var vr2 = new int[][, ][]{new int[, ][]{{new int[]{0}}}};
}
finally
{
if (0UL > s_69[0, 0])
{
var vr3 = new byte[, ]{{0}};
}
else
{
uint[, ] vr4 = new uint[, ]{{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>

0 comments on commit e6a0fd6

Please sign in to comment.