Browse Source

Use brtrue as loop condition only if one of the destinations is not in the loop

pull/70/head
David Srbecký 15 years ago
parent
commit
91334dbfe2
  1. 17
      ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

17
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

@ -464,7 +464,16 @@ namespace ICSharpCode.Decompiler.ILAst @@ -464,7 +464,16 @@ namespace ICSharpCode.Decompiler.ILAst
ILExpression condExpr;
ILLabel trueLabel;
ILLabel falseLabel;
if(basicBlock.MatchBrTure(out condExpr, out trueLabel, out falseLabel)) {
if(basicBlock.MatchBrTure(out condExpr, out trueLabel, out falseLabel))
{
ControlFlowNode trueTarget;
labelToCfNode.TryGetValue(trueLabel, out trueTarget);
ControlFlowNode falseTarget;
labelToCfNode.TryGetValue(falseLabel, out falseTarget);
if ((!loopContents.Contains(trueTarget) && loopContents.Contains(falseTarget)) ||
(loopContents.Contains(trueTarget) && !loopContents.Contains(falseTarget)) )
{
loopContents.RemoveOrThrow(node);
scope.RemoveOrThrow(node);
@ -494,7 +503,11 @@ namespace ICSharpCode.Decompiler.ILAst @@ -494,7 +503,11 @@ namespace ICSharpCode.Decompiler.ILAst
},
FallthoughGoto = null
});
} else {
}
}
// Fallback method: while(true)
if (scope.Contains(node)) {
result.Add(new ILBasicBlock() {
EntryLabel = new ILLabel() { Name = "Loop_" + (nextLabelIndex++) },
Body = new List<ILNode>() {

Loading…
Cancel
Save