Skip to content

Commit

Permalink
- Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Oct 14, 2023
1 parent 919fbb3 commit cf5c6a5
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Source/Data/IR-Optimizations-StrengthReduction-Complex.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@
"Filter": "",
"Result": "(IR.Or## a b)",
"Variations": "Yes"
},
{
"Type": "StrengthReduction",
"Name": "ArithShiftRight64",
"SubName": "By32",
"Expression": "IR.GetLow32 (IR.ArithShiftRight64 (IR.To64 a b) 32)",
"Filter": "",
"Result": "(IR.Move32 b)",
"Variations": "Yes",
"Log": "Yes"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Mosa.Compiler.Framework.CompilerStages;

/// <summary>
/// An compilation stage, which generates a map file of the built binary file.
/// An compilation stage which generates a map file of the built binary file.
/// </summary>
/// <seealso cref="Mosa.Compiler.Framework.BaseCompilerStage" />
public class MethodCompileTimeStage : BaseCompilerStage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ public static class AutoTransforms
new StrengthReduction.Or64Xor64_v1(),
new StrengthReduction.Or64Xor64_v2(),
new StrengthReduction.Or64Xor64_v3(),
new StrengthReduction.ArithShiftRight64By32(),
new Reorder.MulUnsigned32WithShiftLeft32(),
new Reorder.MulUnsigned32WithShiftLeft32_v1(),
new Reorder.MulUnsigned64WithShiftLeft64(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

// This code was generated by an automated template.

namespace Mosa.Compiler.Framework.Transforms.Optimizations.Auto.StrengthReduction;

/// <summary>
/// ArithShiftRight64By32
/// </summary>
[Transform("IR.Optimizations.Auto.StrengthReduction")]
public sealed class ArithShiftRight64By32 : BaseTransform
{
public ArithShiftRight64By32() : base(IRInstruction.GetLow32, TransformType.Auto | TransformType.Optimization, true)
{
}

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

if (!context.Operand1.IsDefinedOnce)
return false;

if (context.Operand1.Definitions[0].Instruction != IRInstruction.ArithShiftRight64)
return false;

if (!context.Operand1.Definitions[0].Operand1.IsVirtualRegister)
return false;

if (!context.Operand1.Definitions[0].Operand2.IsResolvedConstant)
return false;

if (context.Operand1.Definitions[0].Operand2.ConstantUnsigned64 != 32)
return false;

if (!context.Operand1.Definitions[0].Operand1.IsDefinedOnce)
return false;

if (context.Operand1.Definitions[0].Operand1.Definitions[0].Instruction != IRInstruction.To64)
return false;

return true;
}

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

var t1 = context.Operand1.Definitions[0].Operand1.Definitions[0].Operand2;

context.SetInstruction(IRInstruction.Move32, result, t1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.Useless;
[Transform("IR.Optimizations.Manual.Useless")]
public sealed class ZeroExtend8x32Compare32x32 : BaseTransform
{
public ZeroExtend8x32Compare32x32() : base(IRInstruction.ZeroExtend8x32, TransformType.Manual | TransformType.Optimization, true)
public ZeroExtend8x32Compare32x32() : base(IRInstruction.ZeroExtend8x32, TransformType.Manual | TransformType.Optimization)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.Useless;
[Transform("IR.Optimizations.Manual.Useless")]
public sealed class ZeroExtend8x64Compare32x64 : BaseTransform
{
public ZeroExtend8x64Compare32x64() : base(IRInstruction.ZeroExtend8x64, TransformType.Manual | TransformType.Optimization, true)
public ZeroExtend8x64Compare32x64() : base(IRInstruction.ZeroExtend8x64, TransformType.Manual | TransformType.Optimization)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.Useless;
[Transform("IR.Optimizations.Manual.Useless")]
public sealed class ZeroExtend8x64Compare64x64 : BaseTransform
{
public ZeroExtend8x64Compare64x64() : base(IRInstruction.ZeroExtend8x64, TransformType.Manual | TransformType.Optimization, true)
public ZeroExtend8x64Compare64x64() : base(IRInstruction.ZeroExtend8x64, TransformType.Manual | TransformType.Optimization)
{
}

Expand Down

0 comments on commit cf5c6a5

Please sign in to comment.