Skip to content

Commit

Permalink
- WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Oct 21, 2023
1 parent 8dfa87d commit 2d9179b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Source/Mosa.Compiler.Framework/Operand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ public long Offset

public bool IsUsedOnce => Uses.Count == 1;

public bool IsUsedMoreThanOnce => Uses.Count > 1;

public bool IsVirtualRegisterUsed
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@ public override void Transform(Context context, TransformContext transform)
context.AppendInstruction(IRInstruction.GetLow32, op1Low, operand2);
context.AppendInstruction(IRInstruction.GetHigh32, op1High, operand2);

context.SetInstruction(IRInstruction.GetLow32, op0Low, operand1);
context.AppendInstruction(IRInstruction.GetHigh32, op0High, operand1);
context.AppendInstruction(IRInstruction.GetLow32, op1Low, operand2);
context.AppendInstruction(IRInstruction.GetHigh32, op1High, operand2);

context.AppendInstruction(IRInstruction.MulSigned32, v1, op1High, op0Low);
context.AppendInstruction(IRInstruction.MulSigned32, v2, op1Low, op0High);
context.AppendInstruction(IRInstruction.Add32, v4, v2, v1);
context.AppendInstruction(IRInstruction.MulHu32, v3, op1Low, op0Low);
context.AppendInstruction(IRInstruction.MulUnsigned32, v6, op1Low, op0Low);
context.AppendInstruction(IRInstruction.Add32, v4, v2, v1);
context.AppendInstruction(IRInstruction.Add32, v5, v3, v4);

context.AppendInstruction(IRInstruction.To64, result, v6, v5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@ public override void Transform(Context context, TransformContext transform)
context.AppendInstruction(IRInstruction.GetLow32, op1Low, operand2);
context.AppendInstruction(IRInstruction.GetHigh32, op1High, operand2);

context.SetInstruction(IRInstruction.GetLow32, op0Low, operand1);
context.AppendInstruction(IRInstruction.GetHigh32, op0High, operand1);
context.AppendInstruction(IRInstruction.GetLow32, op1Low, operand2);
context.AppendInstruction(IRInstruction.GetHigh32, op1High, operand2);

context.AppendInstruction(IRInstruction.MulSigned32, v1, op1High, op0Low);
context.AppendInstruction(IRInstruction.MulSigned32, v2, op1Low, op0High);
context.AppendInstruction(IRInstruction.Add32, v4, v2, v1);
context.AppendInstruction(IRInstruction.MulHu32, v3, op1Low, op0Low);
context.AppendInstruction(IRInstruction.MulUnsigned32, v6, op1Low, op0Low);
context.AppendInstruction(IRInstruction.Add32, v4, v2, v1);
context.AppendInstruction(IRInstruction.Add32, v5, v3, v4);

context.AppendInstruction(IRInstruction.To64, result, v6, v5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public static class ManualTransforms
//new Special.Mov32Propagate(),
//Add32ToLea32
//Sub32ToLea32

new Special.Mov32Unless(),
new Special.Mov32Coalescing(),

new StrengthReduction.Mul32ByZero(),
new StrengthReduction.Mul32WithMov32ByZero(),

new Special.Mul32Ditto(),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;

namespace Mosa.Compiler.x86.Transforms.Optimizations.Manual.Special;

[Transform("x86.Optimizations.Manual.Special")]
public sealed class Mul32Ditto : BaseTransform
{
public Mul32Ditto() : base(X86.Mul32, TransformType.Manual | TransformType.Optimization)
{
}

public override bool Match(Context context, TransformContext transform)
{
if (transform.AreCPURegistersAllocated)
return false;

if (!context.Result.IsVirtualRegister)
return false;

if (!context.Result2.IsVirtualRegister)
return false;

var previous = context.Node.PreviousNonEmpty;

if (previous == null || previous.Instruction != X86.Mul32)
return false;

if (context.Operand1 != previous.Operand1)
return false;

if (context.Operand2 != previous.Operand2)
return false;

return true;
}

public override void Transform(Context context, TransformContext transform)
{
var previous = context.Node.PreviousNonEmpty;
var result = context.Result;
var result2 = context.Result2;

context.SetInstruction(X86.Mov32, result, previous.Result);
context.AppendInstruction(X86.Mov32, result2, previous.Result2);
}
}

0 comments on commit 2d9179b

Please sign in to comment.