Skip to content

Commit

Permalink
Bug Fix - Check Conversion (#1021)
Browse files Browse the repository at this point in the history
* - Spaces to Tabs

* - Fix spaces to tabs

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - WIP

* - Fixes & WIP
  • Loading branch information
tgiphil committed Feb 12, 2023
1 parent af151ac commit afa7e5f
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 89 deletions.
6 changes: 3 additions & 3 deletions Source/Docs/compiler-optimizations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ Long Expansion
Long Expansion is the transformation of 64-bit instructions into 32-bit instructions for platforms without native 64-bit instructions. This may result in further optimization opportunities.

Devirtualization
Devirtualization is an optimization where virtual method calls are translated into faster static method calls. Devirtualization can happen when the compiler can statically determine at compile which method should be called, so it can produce a direct call to that method, or even inline it.
Devirtualization is an optimization where virtual method calls are translated into faster static method calls. Devirtualization can happen when the compiler can statically determine at compile-time which method are be called, so it can produce a direct call to that method instead, or even inline it.

Null Check Elimination
Null Check Elimination is an optimization that removes null checks instructions when the compiler can statically determine at compile that the object reference is never null.
Null Check Elimination is an optimization that removes null checks instructions when the compiler can statically determine at compile-time that the object reference are never null.

Two Pass Optimizations
This options causes most optimization stages to be executed again, possibility unlocked additional optimizations.
This option causes the optimization stages to be executed again, possibility unlocked additional optimizations.
Original file line number Diff line number Diff line change
Expand Up @@ -2885,7 +2885,7 @@ private bool Ldfld(Context context, Stack<StackEntry> stack, MosaInstruction ins

var isPrimary = IsPrimitive(underlyingType);

var result = AllocatedOperand(stacktype, underlyingType);
var result = AllocatedOperand(stacktype, isPrimary ? underlyingType : type);

PushStack(stack, new StackEntry(stacktype, result));

Expand Down
19 changes: 0 additions & 19 deletions Source/Mosa.Compiler.Framework/Stages/InlineEvaluationStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,6 @@ protected override void Run()
|| node.Instruction == IRInstruction.SetReturnR4
|| node.Instruction == IRInstruction.SetReturnR8
|| node.Instruction == IRInstruction.SetReturnObject
//|| node.Instruction == IRInstruction.LoadParamObject
//|| node.Instruction == IRInstruction.LoadParam32
//|| node.Instruction == IRInstruction.LoadParam64
//|| node.Instruction == IRInstruction.LoadParamCompound
//|| node.Instruction == IRInstruction.LoadParamR4
//|| node.Instruction == IRInstruction.LoadParamR8
//|| node.Instruction == IRInstruction.LoadParamSignExtend16x32
//|| node.Instruction == IRInstruction.LoadParamSignExtend16x64
//|| node.Instruction == IRInstruction.LoadParamSignExtend32x64
//|| node.Instruction == IRInstruction.LoadParamSignExtend8x32
//|| node.Instruction == IRInstruction.LoadParamSignExtend8x64
//|| node.Instruction == IRInstruction.LoadParamZeroExtend16x32
//|| node.Instruction == IRInstruction.LoadParamZeroExtend16x64
//|| node.Instruction == IRInstruction.LoadParamZeroExtend32x64
//|| node.Instruction == IRInstruction.LoadParamZeroExtend8x32
//|| node.Instruction == IRInstruction.LoadParamZeroExtend8x64
|| node.Instruction.IsParameterLoad
//|| node.Instruction == IRInstruction.Epilogue
//|| node.Instruction == IRInstruction.Prologue
|| node.Block.IsEpilogue
|| node.Block.IsPrologue
)
Expand Down
30 changes: 15 additions & 15 deletions Source/Mosa.Demo.TestWorld.x86/Boot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,9 @@ public static void Main()
Screen.WriteLine();
Screen.WriteLine();

//Screen.Write("CompilerBugTests: ");

//bool value1 = Test1();

//if (value1)
// Screen.WriteLine("Ok");
//else
// Screen.WriteLine("Failed");

//Screen.Write("FindTypeOfTest: ");

Test3();
//Test1();

//if (value3)
// Screen.WriteLine("Ok");
Expand All @@ -96,14 +87,23 @@ public static void Main()

TestHash();

int value2 = CallReturn10();
Screen.Write("CheckedTests.MulI8I8: ");

Screen.Write("Return10 Test: ");
if (value2 == 10)
var value1 = Test1();

if (value1 == 0)
Screen.WriteLine("Ok");
else
Screen.WriteLine("Failed");

//int value2 = CallReturn10();

//Screen.Write("Return10 Test: ");
//if (value2 == 10)
// Screen.WriteLine("Ok");
//else
// Screen.WriteLine("Failed");

StartThreadTest();

// should never get here
Expand Down Expand Up @@ -288,9 +288,9 @@ public static int CallReturn10()
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static bool Test1()
public static long Test1()
{
return CompilerBugTests.Test();
return UnitTests.Primitive.CheckedTests.MulI8I8(0, 0);
}

[MethodImpl(MethodImplOptions.NoInlining)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override bool Match(Context context, TransformContext transform)

public override void Transform(Context context, TransformContext transform)
{
var methodName = "mul64carry";
var methodName = "Mul64Carry";
var method = transform.GetMethod("Mosa.Runtime.Math.Multiplication", methodName);

var operand1 = context.Operand1;
Expand All @@ -39,7 +39,7 @@ public override void Transform(Context context, TransformContext transform)

context.SetInstruction(IRInstruction.AddressOf, v2, v1);
context.AppendInstruction(IRInstruction.CallStatic, result, symbol, operand1, operand2, v2);
context.AppendInstruction(IRInstruction.Load32, result2, v2, transform.Constant32_0);
context.AppendInstruction(IRInstruction.LoadZeroExtend8x32, result2, v2, transform.Constant32_0);

transform.MethodCompiler.MethodScanner.MethodInvoked(method, transform.MethodCompiler.Method);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override bool Match(Context context, TransformContext transform)

public override void Transform(Context context, TransformContext transform)
{
var methodName = "mul64overflow";
var methodName = "Mul64Overflow";
var method = transform.GetMethod("Mosa.Runtime.Math.Multiplication", methodName);

var operand1 = context.Operand1;
Expand All @@ -39,7 +39,7 @@ public override void Transform(Context context, TransformContext transform)

context.SetInstruction(IRInstruction.AddressOf, v2, v1);
context.AppendInstruction(IRInstruction.CallStatic, result, symbol, operand1, operand2, v2);
context.AppendInstruction(IRInstruction.Load32, result2, v2, transform.Constant32_0);
context.AppendInstruction(IRInstruction.LoadZeroExtend8x32, result2, v2, transform.Constant32_0);

transform.MethodCompiler.MethodScanner.MethodInvoked(method, transform.MethodCompiler.Method);
}
Expand Down

0 comments on commit afa7e5f

Please sign in to comment.