From 5cf6180815992af7d90803a989094bfc2616f617 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Tue, 19 Jul 2022 13:45:04 +0200 Subject: [PATCH 1/4] test --- src/coreclr/jit/redundantbranchopts.cpp | 3 +- .../JitBlue/Runtime_71599/Runtime_71599.cs | 114 ++++++++++++++++++ .../Runtime_71599/Runtime_71599.csproj | 9 ++ 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_71599/Runtime_71599.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_71599/Runtime_71599.csproj diff --git a/src/coreclr/jit/redundantbranchopts.cpp b/src/coreclr/jit/redundantbranchopts.cpp index 19f3fb5e35c63..6d4cf1609c3c7 100644 --- a/src/coreclr/jit/redundantbranchopts.cpp +++ b/src/coreclr/jit/redundantbranchopts.cpp @@ -390,7 +390,8 @@ bool Compiler::optRedundantBranch(BasicBlock* const block) const bool trueReaches = optReachable(trueSuccessor, block, domBlock); const bool falseReaches = optReachable(falseSuccessor, block, domBlock); - if (trueReaches && falseReaches && rii.canInferFromTrue && rii.canInferFromFalse) + if (trueReaches && falseReaches && rii.canInferFromTrue && rii.canInferFromFalse && + (fgCurBBEpochSize == (fgDomBBcount + 1)) { // JIT-TP: it didn't produce diffs so let's skip it if (trySpeculativeDom) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_71599/Runtime_71599.cs b/src/tests/JIT/Regression/JitBlue/Runtime_71599/Runtime_71599.cs new file mode 100644 index 0000000000000..06b536fdb35d2 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_71599/Runtime_71599.cs @@ -0,0 +1,114 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// Generated by Fuzzlyn v1.5 on 2022-07-03 16:41:26 +// Run on Arm64 MacOS +// Seed: 15254214336696406464 +// Reduced from 47.2 KiB to 1.6 KiB in 00:00:23 +// Hits JIT assert in Release: +// Assertion failed 'i < BitSetTraits::GetSize(env)' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Redundant branch opts' (IL size 260; hash 0xade6b36b; FullOpts) +// +// File: /Users/runner/work/1/s/src/coreclr/jit/bitsetasshortlong.h Line: 261 +// + +using System; + +public class C0 +{ + public ushort F0; + public ulong F1; +} + +public class C1 +{ + public C0 F0; + public C0 F3; + public C0 F6; +} + +public struct S0 +{ + public bool F1; + public ushort F3; + public byte F6; +} + +public struct S1 +{ + public int F0; +} + +public class Runtime_71599 +{ + public static IRuntime s_rt; + public static C1[] s_1; + public static S0[] s_3; + public static S1 s_7; + + public static int Main() + { + try + { + Test(); + } + catch (NullReferenceException) + { + return 100; + } + return 101; + } + + + public static void Test() + { + ushort[] vr2 = default(ushort[]); + S0 vr3 = default(S0); + bool vr4 = vr3.F1; + byte vr5 = vr3.F6--; + if (vr4) + { + try + { + s_rt.WriteLine(1); + } + finally + { + C1 vr6 = s_1[0]; + var vr7 = new long[] { 1 }; + var vr8 = vr6.F3; + long[] vr10 = vr7; + C0 vr11 = vr8; + int vr13 = s_7.F0; + s_rt.WriteLine(vr6.F0.F0); + s_rt.WriteLine(vr6.F0.F1); + s_rt.WriteLine(vr6.F6.F0); + } + + if (!vr4) + { + s_1[0].F3.F0 = vr3.F3; + } + } + + for (int vr9 = 0; vr9 < 2; vr9++) + { + if (vr4) + { + s_3[0].F3 = vr2[0]; + } + + s_rt.WriteLine(vr9); + } + + } +} + +public interface IRuntime +{ + void WriteLine(T value); +} + +public class Runtime : IRuntime +{ + public void WriteLine(T value) => System.Console.WriteLine(value); +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_71599/Runtime_71599.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_71599/Runtime_71599.csproj new file mode 100644 index 0000000000000..f492aeac9d056 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_71599/Runtime_71599.csproj @@ -0,0 +1,9 @@ + + + Exe + True + + + + + \ No newline at end of file From 0435da03b77e2e91b3e69156cc14eebfde97cb66 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Tue, 19 Jul 2022 13:50:48 +0200 Subject: [PATCH 2/4] test --- src/coreclr/jit/redundantbranchopts.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/redundantbranchopts.cpp b/src/coreclr/jit/redundantbranchopts.cpp index 6d4cf1609c3c7..c2866f1f4ffd0 100644 --- a/src/coreclr/jit/redundantbranchopts.cpp +++ b/src/coreclr/jit/redundantbranchopts.cpp @@ -391,7 +391,7 @@ bool Compiler::optRedundantBranch(BasicBlock* const block) const bool falseReaches = optReachable(falseSuccessor, block, domBlock); if (trueReaches && falseReaches && rii.canInferFromTrue && rii.canInferFromFalse && - (fgCurBBEpochSize == (fgDomBBcount + 1)) + (fgCurBBEpochSize == (fgDomBBcount + 1))) { // JIT-TP: it didn't produce diffs so let's skip it if (trySpeculativeDom) From 832ceb34e1429b7b7845857e57bb2bd2bb7bafd7 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Tue, 19 Jul 2022 13:55:18 +0200 Subject: [PATCH 3/4] clean up --- src/coreclr/jit/redundantbranchopts.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/redundantbranchopts.cpp b/src/coreclr/jit/redundantbranchopts.cpp index c2866f1f4ffd0..d3db940c795f5 100644 --- a/src/coreclr/jit/redundantbranchopts.cpp +++ b/src/coreclr/jit/redundantbranchopts.cpp @@ -390,8 +390,7 @@ bool Compiler::optRedundantBranch(BasicBlock* const block) const bool trueReaches = optReachable(trueSuccessor, block, domBlock); const bool falseReaches = optReachable(falseSuccessor, block, domBlock); - if (trueReaches && falseReaches && rii.canInferFromTrue && rii.canInferFromFalse && - (fgCurBBEpochSize == (fgDomBBcount + 1))) + if (trueReaches && falseReaches && rii.canInferFromTrue && rii.canInferFromFalse) { // JIT-TP: it didn't produce diffs so let's skip it if (trySpeculativeDom) @@ -399,6 +398,12 @@ bool Compiler::optRedundantBranch(BasicBlock* const block) break; } + if (fgCurBBEpochSize != (fgBBNumMax + 1)) + { + // We added new blocks since the last renumerate e.g. in optLoopHoist + break; + } + // Both dominating compare outcomes reach the current block so we can't infer the // value of the relop. // From 6fcea8497ebab5cf02f6c7b8aa25cfd243463d87 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Tue, 19 Jul 2022 18:16:47 +0200 Subject: [PATCH 4/4] Address feedback --- src/coreclr/jit/redundantbranchopts.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/coreclr/jit/redundantbranchopts.cpp b/src/coreclr/jit/redundantbranchopts.cpp index d3db940c795f5..3be61ed47a523 100644 --- a/src/coreclr/jit/redundantbranchopts.cpp +++ b/src/coreclr/jit/redundantbranchopts.cpp @@ -398,12 +398,6 @@ bool Compiler::optRedundantBranch(BasicBlock* const block) break; } - if (fgCurBBEpochSize != (fgBBNumMax + 1)) - { - // We added new blocks since the last renumerate e.g. in optLoopHoist - break; - } - // Both dominating compare outcomes reach the current block so we can't infer the // value of the relop. // @@ -559,6 +553,12 @@ bool Compiler::optJumpThread(BasicBlock* const block, BasicBlock* const domBlock assert(block->bbJumpKind == BBJ_COND); assert(domBlock->bbJumpKind == BBJ_COND); + if (fgCurBBEpochSize != (fgBBNumMax + 1)) + { + JITDUMP("Looks like we've added a new block (e.g. during optLoopHoist) since last renumber, so no threading\n"); + return false; + } + // If the dominating block is not the immediate dominator // we might need to duplicate a lot of code to thread // the jumps. See if that's the case.