Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve block ordering in ConditionDetection using the ILOffsets of Leave instruction arguments #1218

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/ShortCircuit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ public int StmtComplex6()
return 2;
}

public int InferCorrectOrder()
{
if (F(1) || F(2)) {
return 1;
}
return 2;
}

#if !OPT
public void EmptyIf()
{
Expand All @@ -268,5 +276,14 @@ public void EmptyIf()
E();
}
#endif

public void PreferLogicalToBitwise(bool a, bool b, int i, float f)
{
B(a && b);
B(a && i == 1);
B(i == 1 && a);
B(i > i - 3 && a);
B(f < 0.1f && a);
}
}
}
113 changes: 113 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/ShortCircuit.il
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,45 @@
IL_003d: ret
} // end of method ShortCircuit::StmtComplex6

.method public hidebysig instance int32
InferCorrectOrder() cil managed
{
// Code size 39 (0x27)
.maxstack 2
.locals init (int32 V_0,
bool V_1)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldc.i4.1
IL_0003: callvirt instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::F(int32)
IL_0008: brtrue.s IL_0016

IL_000a: ldarg.0
IL_000b: ldc.i4.2
IL_000c: callvirt instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::F(int32)
IL_0011: ldc.i4.0
IL_0012: ceq
IL_0014: br.s IL_0017

IL_0016: ldc.i4.0
IL_0017: nop
IL_0018: stloc.1
IL_0019: ldloc.1
IL_001a: brtrue.s IL_0021

IL_001c: nop
IL_001d: ldc.i4.1
IL_001e: stloc.0
IL_001f: br.s IL_0025

IL_0021: ldc.i4.2
IL_0022: stloc.0
IL_0023: br.s IL_0025

IL_0025: ldloc.0
IL_0026: ret
} // end of method ShortCircuit::InferCorrectOrder

.method public hidebysig instance void
EmptyIf() cil managed
{
Expand Down Expand Up @@ -1369,6 +1408,80 @@
IL_009b: ret
} // end of method ShortCircuit::EmptyIf

.method public hidebysig instance void
PreferLogicalToBitwise(bool a,
bool b,
int32 i,
float32 f) cil managed
{
// Code size 90 (0x5a)
.maxstack 4
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldarg.1
IL_0003: brfalse.s IL_0008

IL_0005: ldarg.2
IL_0006: br.s IL_0009

IL_0008: ldc.i4.0
IL_0009: nop
IL_000a: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_000f: nop
IL_0010: ldarg.0
IL_0011: ldarg.1
IL_0012: brfalse.s IL_001a

IL_0014: ldarg.3
IL_0015: ldc.i4.1
IL_0016: ceq
IL_0018: br.s IL_001b

IL_001a: ldc.i4.0
IL_001b: nop
IL_001c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_0021: nop
IL_0022: ldarg.0
IL_0023: ldarg.3
IL_0024: ldc.i4.1
IL_0025: bne.un.s IL_002a

IL_0027: ldarg.1
IL_0028: br.s IL_002b

IL_002a: ldc.i4.0
IL_002b: nop
IL_002c: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_0031: nop
IL_0032: ldarg.0
IL_0033: ldarg.3
IL_0034: ldarg.3
IL_0035: ldc.i4.3
IL_0036: sub
IL_0037: ble.s IL_003c

IL_0039: ldarg.1
IL_003a: br.s IL_003d

IL_003c: ldc.i4.0
IL_003d: nop
IL_003e: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_0043: nop
IL_0044: ldarg.0
IL_0045: ldarg.s f
IL_0047: ldc.r4 0.1
IL_004c: bge.un.s IL_0051

IL_004e: ldarg.1
IL_004f: br.s IL_0052

IL_0051: ldc.i4.0
IL_0052: nop
IL_0053: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_0058: nop
IL_0059: ret
} // end of method ShortCircuit::PreferLogicalToBitwise

.method family hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
Expand Down
85 changes: 85 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/ShortCircuit.opt.il
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,91 @@
IL_0024: ret
} // end of method ShortCircuit::StmtComplex6

.method public hidebysig instance int32
InferCorrectOrder() cil managed
{
// Code size 22 (0x16)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldc.i4.1
IL_0002: callvirt instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::F(int32)
IL_0007: brtrue.s IL_0012

IL_0009: ldarg.0
IL_000a: ldc.i4.2
IL_000b: callvirt instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::F(int32)
IL_0010: brfalse.s IL_0014

IL_0012: ldc.i4.1
IL_0013: ret

IL_0014: ldc.i4.2
IL_0015: ret
} // end of method ShortCircuit::InferCorrectOrder

.method public hidebysig instance void
PreferLogicalToBitwise(bool a,
bool b,
int32 i,
float32 f) cil managed
{
// Code size 79 (0x4f)
.maxstack 4
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: brfalse.s IL_0007

IL_0004: ldarg.2
IL_0005: br.s IL_0008

IL_0007: ldc.i4.0
IL_0008: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_000d: ldarg.0
IL_000e: ldarg.1
IL_000f: brfalse.s IL_0017

IL_0011: ldarg.3
IL_0012: ldc.i4.1
IL_0013: ceq
IL_0015: br.s IL_0018

IL_0017: ldc.i4.0
IL_0018: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_001d: ldarg.0
IL_001e: ldarg.3
IL_001f: ldc.i4.1
IL_0020: bne.un.s IL_0025

IL_0022: ldarg.1
IL_0023: br.s IL_0026

IL_0025: ldc.i4.0
IL_0026: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_002b: ldarg.0
IL_002c: ldarg.3
IL_002d: ldarg.3
IL_002e: ldc.i4.3
IL_002f: sub
IL_0030: ble.s IL_0035

IL_0032: ldarg.1
IL_0033: br.s IL_0036

IL_0035: ldc.i4.0
IL_0036: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_003b: ldarg.0
IL_003c: ldarg.s f
IL_003e: ldc.r4 0.1
IL_0043: bge.un.s IL_0048

IL_0045: ldarg.1
IL_0046: br.s IL_0049

IL_0048: ldc.i4.0
IL_0049: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_004e: ret
} // end of method ShortCircuit::PreferLogicalToBitwise

.method family hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,78 @@
IL_0024: ret
} // end of method ShortCircuit::StmtComplex6

.method public hidebysig instance int32
InferCorrectOrder() cil managed
{
// Code size 22 (0x16)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldc.i4.1
IL_0002: callvirt instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::F(int32)
IL_0007: brtrue.s IL_0012

IL_0009: ldarg.0
IL_000a: ldc.i4.2
IL_000b: callvirt instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::F(int32)
IL_0010: brfalse.s IL_0014

IL_0012: ldc.i4.1
IL_0013: ret

IL_0014: ldc.i4.2
IL_0015: ret
} // end of method ShortCircuit::InferCorrectOrder

.method public hidebysig instance void
PreferLogicalToBitwise(bool a,
bool b,
int32 i,
float32 f) cil managed
{
// Code size 69 (0x45)
.maxstack 4
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: and
IL_0004: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_0009: ldarg.0
IL_000a: ldarg.1
IL_000b: brfalse.s IL_0013

IL_000d: ldarg.3
IL_000e: ldc.i4.1
IL_000f: ceq
IL_0011: br.s IL_0014

IL_0013: ldc.i4.0
IL_0014: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_0019: ldarg.0
IL_001a: ldarg.3
IL_001b: ldc.i4.1
IL_001c: ceq
IL_001e: ldarg.1
IL_001f: and
IL_0020: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_0025: ldarg.0
IL_0026: ldarg.3
IL_0027: ldarg.3
IL_0028: ldc.i4.3
IL_0029: sub
IL_002a: cgt
IL_002c: ldarg.1
IL_002d: and
IL_002e: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_0033: ldarg.0
IL_0034: ldarg.s f
IL_0036: ldc.r4 0.1
IL_003b: clt
IL_003d: ldarg.1
IL_003e: and
IL_003f: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.ShortCircuit::B(bool)
IL_0044: ret
} // end of method ShortCircuit::PreferLogicalToBitwise

.method family hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
Expand Down
Loading