Skip to content

Commit

Permalink
- WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Nov 15, 2023
1 parent fd96ffa commit 744fd44
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Source/Data/X86-Optimizations-Lea.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"Result": "(X86.Mov32 a)",
"Variations": "No",
"Log": "Yes"
},
{
"Type": "Rewrite",
"Name": "Lea32",
"SubName": "RemoveScale",
"Expression": "X86.Lea32 a 0 c d",
"Filter": "!IsOne(c)",
"Result": "(X86.Lea32 a 0 1 d)",
"Variations": "No",
"Log": "Yes"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ public static class AutoTransforms
new Rewrite.Lea32Shift32(),
new Rewrite.Lea32ToMov32Constant1(),
new Rewrite.Lea32ToMov32Constant2(),
new Rewrite.Lea32RemoveScale(),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

// This code was generated by an automated template.

using Mosa.Compiler.Framework;

namespace Mosa.Compiler.x86.Transforms.Optimizations.Auto.Rewrite;

[Transform("x86.Optimizations.Auto.Rewrite")]
public sealed class Lea32RemoveScale : BaseTransform
{
public Lea32RemoveScale() : base(X86.Lea32, TransformType.Auto | TransformType.Optimization, true)
{
}

public override bool Match(Context context, Transform transform)
{
if (!context.Operand2.IsConstantZero)
return false;

if (IsOne(context.Operand3))
return false;

return true;
}

public override void Transform(Context context, Transform transform)
{
var result = context.Result;

var t1 = context.Operand1;
var t2 = context.GetOperand(3);

var c1 = Operand.CreateConstant(0);
var c2 = Operand.CreateConstant(1);

context.SetInstruction(X86.Lea32, result, t1, c1, c2, t2);
}
}

0 comments on commit 744fd44

Please sign in to comment.