From fc73851bb4f90c09818845982b24aceb4d79e7f8 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 4 Aug 2019 14:12:15 +0200 Subject: [PATCH] #1610: Slightly more aggressive copy propagation. This helps clean up the mess left behind when stack slots are not eliminated by the normal transforms. We previously didn't do this because aggressive copy propagation could confuse the normal transforms; but this is no longer an issue with the new pass ordering. --- .../IL/Transforms/CopyPropagation.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs b/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs index d4e867e7f..3ccf25e02 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs @@ -105,13 +105,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms // Parameters can be copied only if they aren't assigned to (directly or indirectly via ldarga) // note: the initialization by the caller is the first store -> StoreCount must be 1 return v.IsSingleDefinition; - case VariableKind.StackSlot: - case VariableKind.ExceptionStackSlot: - // Variables are be copied only if both they and the target copy variable are generated, - // and if the variable has only a single assignment - return v.IsSingleDefinition && target.Kind == VariableKind.StackSlot; default: - return false; + // Variables can be copied if both are single-definition. + // To avoid removing too many variables, we do this only if the target + // is either a stackslot or a ref local. + Debug.Assert(target.IsSingleDefinition); + return v.IsSingleDefinition && (target.Kind == VariableKind.StackSlot || target.StackType == StackType.Ref); } default: // All instructions without special behavior that target a stack-variable can be copied.