Browse Source

Optimize: MOVE Unm Pattern

Akeit0 1 year ago
parent
commit
f9862f0b5a
1 changed files with 11 additions and 0 deletions
  1. 11 0
      src/Lua/CodeAnalysis/Compilation/FunctionCompilationContext.cs

+ 11 - 0
src/Lua/CodeAnalysis/Compilation/FunctionCompilationContext.cs

@@ -198,6 +198,17 @@ public class FunctionCompilationContext : IDisposable
                 }
                 }
                 break;
                 break;
             }
             }
+            case OpCode.Unm:
+                if (lastInstruction.OpCode == OpCode.Move && lastLocal != lastInstruction.A)
+                {
+                    if (lastInstruction.A == instruction.B)
+                    {
+                        lastInstruction=Instruction.Unm(instruction.A, lastInstruction.B);
+                        incrementStackPosition = false;
+                        return;
+                    }
+                }
+                break;
         }
         }
         
         
         instructions.Add(instruction);
         instructions.Add(instruction);