Skip to content

Commit c20e872

Browse files
author
Maksim Volkau
committed
added more checks
1 parent 8ce6706 commit c20e872

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

src/FastExpressionCompiler/FastExpressionCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5636,7 +5636,7 @@ private static bool TryEmitSwitch(SwitchExpression expr, IReadOnlyList<PE> param
56365636
for (var i = 0; i < caseCount; ++i)
56375637
{
56385638
var cs = cases[i];
5639-
if (i == minOutlierCaseBodyIdx || i == maxOutlierCaseBodyIdx)
5639+
if (i == minOutlierCaseBodyIdx | i == maxOutlierCaseBodyIdx)
56405640
il.DmarkLabel(i == minOutlierCaseBodyIdx ? minOutlierLabel : maxOutlierLabel);
56415641
else
56425642
{

test/FastExpressionCompiler.IssueTests/Issue398_Optimize_Switch_with_OpCodes_Switch.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,54 @@ public void Test_switch_with_first_and_last_outliers(TestContext t)
471471
);
472472

473473
t.IsNotNull(fs);
474+
t.AreEqual(-3, fs(-10));
475+
t.AreEqual(-3, fs(3));
476+
t.AreEqual(4, fs(4));
474477
t.AreEqual(4, fs(5));
478+
t.AreEqual(4, fs(4));
479+
t.AreEqual(6, fs(6));
480+
t.AreEqual(7, fs(7));
481+
t.AreEqual(20, fs(20));
475482

476483
var ff = expr.CompileFast();
477484
ff.PrintIL(format: ILFormat.AssertOpCodes);
485+
ff.AssertOpCodes(
486+
OpCodes.Ldarg_1, // at IL_0000
487+
OpCodes.Stloc_0, // at IL_0001
488+
OpCodes.Ldloc_0, // at IL_0002
489+
OpCodes.Ldc_I4_S, // 246 at IL_0003
490+
OpCodes.Beq, // IL_0051 at IL_0005
491+
OpCodes.Ldloc_0, // at IL_0010
492+
OpCodes.Ldc_I4_3, // at IL_0011
493+
OpCodes.Sub, // at IL_0012
494+
OpCodes.Switch, // [IL_0051, IL_0058, IL_0058, IL_0064, IL_0070] at IL_0013
495+
OpCodes.Ldloc_0, // at IL_0038
496+
OpCodes.Ldc_I4_S, // 20 at IL_0039
497+
OpCodes.Beq, // IL_0076 at IL_0041
498+
OpCodes.Br, // IL_0083 at IL_0046
499+
OpCodes.Ldc_I4_S, // 253 at IL_0051
500+
OpCodes.Br, // IL_0084 at IL_0053
501+
OpCodes.Ldc_I4_4, // at IL_0058
502+
OpCodes.Br, // IL_0084 at IL_0059
503+
OpCodes.Ldc_I4_6, // at IL_0064
504+
OpCodes.Br, // IL_0084 at IL_0065
505+
OpCodes.Ldc_I4_7, // at IL_0070
506+
OpCodes.Br, // IL_0084 at IL_0071
507+
OpCodes.Ldc_I4_S, // 20 at IL_0076
508+
OpCodes.Br, // IL_0084 at IL_0078
509+
OpCodes.Ldc_I4_M1, // at IL_0083
510+
OpCodes.Ret // at IL_0084
511+
);
478512

479513
t.IsNotNull(ff);
480-
t.AreEqual(5, ff(5));
514+
t.AreEqual(-3, fs(-10));
515+
t.AreEqual(-3, fs(3));
516+
t.AreEqual(4, fs(4));
517+
t.AreEqual(4, fs(5));
518+
t.AreEqual(4, fs(4));
519+
t.AreEqual(6, fs(6));
520+
t.AreEqual(7, fs(7));
521+
t.AreEqual(20, fs(20));
481522
}
482523

483524
public void Test_switch_for_the_bytes_two_ranges_NOT_SUPPORTED_YET(TestContext t)

0 commit comments

Comments
 (0)