From e53c2565e8c2dc139f32ab9ce39b48473270f7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Mon, 28 Feb 2011 00:07:58 +0000 Subject: [PATCH] Simple heuristics to improve gotos related to loops --- ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs b/ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs index 73760eb7f..f214dc48a 100644 --- a/ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs +++ b/ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs @@ -463,6 +463,17 @@ namespace Decompiler.ControlFlow scope.Remove(node); branchExpr.Operand = null; // Do not keep label alive + // TODO: Does 'true' really point into the loop body? Swap if necessary + + ControlFlowNode postLoopTarget; + labelToCfNode.TryGetValue(falseLabel, out postLoopTarget); + if (postLoopTarget != null) { + // Pull more nodes into the loop + HashSet postLoopContents = FindDominatedNodes(scope, postLoopTarget); + var pullIn = scope.Except(postLoopContents).Where(n => node.Dominates(n)); + loopContents.UnionWith(pullIn); + } + // Use loop to implement the condition result.Add(new ILBasicBlock() { EntryLabel = basicBlock.EntryLabel,