Skip to content

Commit

Permalink
Skip the balanced switch dispatch optimization for patterns on floati…
Browse files Browse the repository at this point in the history
…ng-point inputs (#62322)
  • Loading branch information
jcouv authored Jul 6, 2022
1 parent af92deb commit 04a4764
Show file tree
Hide file tree
Showing 4 changed files with 807 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,13 @@ bool canDispatch(BoundTestDecisionDagNode test1, BoundTestDecisionDagNode test2)
return false;
if (!t1.Input.Equals(t2.Input))
return false;

if (t1.Input.Type.SpecialType is SpecialType.System_Double or SpecialType.System_Single)
{
// The optimization (using balanced switch dispatch) breaks the semantics of NaN
return false;
}

return true;
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/Compilers/CSharp/Test/Emit/CodeGen/PatternTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,11 @@ .locals init (object V_0,
IL_000e: unbox.any ""double""
IL_0013: stloc.1
IL_0014: ldloc.1
IL_0015: ldc.r8 3.14
IL_001e: beq.s IL_0055
IL_0020: ldloc.1
IL_0021: call ""bool double.IsNaN(double)""
IL_0026: brtrue.s IL_004b
IL_0015: call ""bool double.IsNaN(double)""
IL_001a: brtrue.s IL_004b
IL_001c: ldloc.1
IL_001d: ldc.r8 3.14
IL_0026: beq.s IL_0055
IL_0028: br.s IL_005f
IL_002a: ldloc.0
IL_002b: isinst ""float""
Expand All @@ -571,11 +571,11 @@ .locals init (object V_0,
IL_0033: unbox.any ""float""
IL_0038: stloc.2
IL_0039: ldloc.2
IL_003a: ldc.r4 3.14
IL_003f: beq.s IL_005a
IL_003a: call ""bool float.IsNaN(float)""
IL_003f: brtrue.s IL_0050
IL_0041: ldloc.2
IL_0042: call ""bool float.IsNaN(float)""
IL_0047: brtrue.s IL_0050
IL_0042: ldc.r4 3.14
IL_0047: beq.s IL_005a
IL_0049: br.s IL_005f
IL_004b: ldc.i4.1
IL_004c: stloc.s V_4
Expand Down
Loading

0 comments on commit 04a4764

Please sign in to comment.