From e6a0fd6e7f3e3186a6861e0e161cec1357c6a340 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Mon, 24 Jun 2024 14:51:55 -0700 Subject: [PATCH] Don't fold relops with side effects that are used in jumps (#103903) * Don't fold relops with side effects that are used in jumps * Reorder comparisons --- src/coreclr/jit/gentree.cpp | 8 +++ .../Runtime_102138.cs | 0 .../Runtime_102138.csproj | 0 .../JitBlue/Runtime_103888/Runtime_103888.cs | 59 +++++++++++++++++++ .../Runtime_103888/Runtime_103888.csproj | 8 +++ 5 files changed, 75 insertions(+) rename src/tests/JIT/Regression/JitBlue/{Runtime_1102138 => Runtime_102138}/Runtime_102138.cs (100%) rename src/tests/JIT/Regression/JitBlue/{Runtime_1102138 => Runtime_102138}/Runtime_102138.csproj (100%) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_103888/Runtime_103888.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_103888/Runtime_103888.csproj diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 713708f311fa8..66b02be988bf0 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -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: diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_1102138/Runtime_102138.cs b/src/tests/JIT/Regression/JitBlue/Runtime_102138/Runtime_102138.cs similarity index 100% rename from src/tests/JIT/Regression/JitBlue/Runtime_1102138/Runtime_102138.cs rename to src/tests/JIT/Regression/JitBlue/Runtime_102138/Runtime_102138.cs diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_1102138/Runtime_102138.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_102138/Runtime_102138.csproj similarity index 100% rename from src/tests/JIT/Regression/JitBlue/Runtime_1102138/Runtime_102138.csproj rename to src/tests/JIT/Regression/JitBlue/Runtime_102138/Runtime_102138.csproj diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_103888/Runtime_103888.cs b/src/tests/JIT/Regression/JitBlue/Runtime_103888/Runtime_103888.cs new file mode 100644 index 0000000000000..aab4c13a324ce --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_103888/Runtime_103888.cs @@ -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}}; + } + } + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_103888/Runtime_103888.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_103888/Runtime_103888.csproj new file mode 100644 index 0000000000000..de6d5e08882e8 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_103888/Runtime_103888.csproj @@ -0,0 +1,8 @@ + + + True + + + + +