Browse Source

Remove hack that prevented inlining of the first instruction in each block.

Now that ILReader already creates the basic blocks and BlockBuilder only arranges them in containers, this code is no longer necessary.
pull/2993/head
Daniel Grunwald 2 years ago
parent
commit
b9ce8490f5
  1. 10
      ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs
  2. 8
      ICSharpCode.Decompiler/IL/ILReader.cs

10
ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs

@ -258,7 +258,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
if (targetBlock.StartILOffset < block.StartILOffset && IsDeadTrueStore(block)) if (targetBlock.StartILOffset < block.StartILOffset && IsDeadTrueStore(block))
{ {
// The C# compiler generates a dead store for the condition of while (true) loops. // The C# compiler generates a dead store for the condition of while (true) loops.
block.Instructions.RemoveRange(block.Instructions.Count - 3, 2); block.Instructions.RemoveAt(block.Instructions.Count - 2);
} }
if (block.ILRangeIsEmpty) if (block.ILRangeIsEmpty)
@ -275,15 +275,13 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
/// </summary> /// </summary>
private static bool IsDeadTrueStore(Block block) private static bool IsDeadTrueStore(Block block)
{ {
if (block.Instructions.Count < 3) if (block.Instructions.Count < 2)
return false; return false;
if (!(block.Instructions.SecondToLastOrDefault() is StLoc deadStore && block.Instructions[block.Instructions.Count - 3] is StLoc tempStore)) if (!(block.Instructions.SecondToLastOrDefault() is StLoc deadStore))
return false; return false;
if (!(deadStore.Variable.LoadCount == 0 && deadStore.Variable.AddressCount == 0)) if (!(deadStore.Variable.LoadCount == 0 && deadStore.Variable.AddressCount == 0))
return false; return false;
if (!(deadStore.Value.MatchLdLoc(tempStore.Variable) && tempStore.Variable.IsSingleDefinition && tempStore.Variable.LoadCount == 1)) return deadStore.Value.MatchLdcI4(1) && deadStore.Variable.Type.IsKnownType(KnownTypeCode.Boolean);
return false;
return tempStore.Value.MatchLdcI4(1) && deadStore.Variable.Type.IsKnownType(KnownTypeCode.Boolean);
} }
} }
} }

8
ICSharpCode.Decompiler/IL/ILReader.cs

@ -514,14 +514,6 @@ namespace ICSharpCode.Decompiler.IL
FlushExpressionStack(); FlushExpressionStack();
block.Block.Instructions.Add(inst); block.Block.Instructions.Add(inst);
} }
else if (start == block.StartILOffset)
{
// If this instruction is the first in a new block, avoid it being inlined
// into the next instruction.
// This is necessary because the BlockBuilder uses inst.StartILOffset to
// detect block starts, and doesn't search nested instructions.
FlushExpressionStack();
}
if ((!decodedInstruction.PushedOnExpressionStack && IsSequencePointInstruction(inst)) || startedWithEmptyStack) if ((!decodedInstruction.PushedOnExpressionStack && IsSequencePointInstruction(inst)) || startedWithEmptyStack)
{ {

Loading…
Cancel
Save