diff --git a/Source/Data/IR-Optimizations-BitValue.json b/Source/Data/IR-Optimizations-BitValue.json
index 44824dbfed..7669828254 100644
--- a/Source/Data/IR-Optimizations-BitValue.json
+++ b/Source/Data/IR-Optimizations-BitValue.json
@@ -41,7 +41,7 @@
"Result": "(IR.MulUnsigned## a b)",
"Priority": "20",
"Variations": "Yes",
- "Log": "Yes"
+ "Log": "No"
},
{
"Type": "BitValue",
@@ -52,7 +52,7 @@
"Result": "(IR.RemUnsigned## a b)",
"Priority": "20",
"Variations": "No",
- "Log": "Yes"
+ "Log": "No"
},
{
"Type": "BitValue",
@@ -63,7 +63,7 @@
"Result": "(IR.ShiftRight## a b)",
"Priority": "20",
"Variations": "No",
- "Log": "Yes"
+ "Log": "No"
}
]
}
diff --git a/Source/Data/IR-Optimizations-Simplification.json b/Source/Data/IR-Optimizations-Simplification.json
index ffdb0a3eef..3fe358e827 100644
--- a/Source/Data/IR-Optimizations-Simplification.json
+++ b/Source/Data/IR-Optimizations-Simplification.json
@@ -38,7 +38,8 @@
"SubName": "Coalescing",
"Expression": "IR.Move## (IR.Move## a)",
"Filter": "!IsCPURegister(a)",
- "Result": "(IR.Move## a)"
+ "Result": "(IR.Move## a)",
+ "Priority": "25"
},
{
"Type": "Simplification",
@@ -46,7 +47,8 @@
"SubName": "Coalescing",
"Expression": "IR.MoveObject (IR.MoveObject a)",
"Filter": "",
- "Result": "(IR.MoveObject a)"
+ "Result": "(IR.MoveObject a)",
+ "Priority": "25"
},
{
"Type": "Simplification",
@@ -54,7 +56,8 @@
"SubName": "Coalescing",
"Expression": "IR.MoveManagedPointer (IR.MoveManagedPointer a)",
"Filter": "",
- "Result": "(IR.MoveManagedPointer a)"
+ "Result": "(IR.MoveManagedPointer a)",
+ "Priority": "25"
},
{
"Type": "Simplification",
@@ -62,7 +65,8 @@
"SubName": "Twice",
"Expression": "IR.Not## (IR.Not## x)",
"Filter": "",
- "Result": "(IR.Move## x)"
+ "Result": "(IR.Move## x)",
+ "Priority": "25"
},
{
"Type": "Simplification",
@@ -70,7 +74,8 @@
"SubName": "FromTo64",
"Expression": "IR.GetLow32 (IR.To64 a b))",
"Filter": "",
- "Result": "(IR.Move32 a)"
+ "Result": "(IR.Move32 a)",
+ "Priority": "25"
},
{
"Type": "Simplification",
@@ -78,7 +83,8 @@
"SubName": "FromTo64",
"Expression": "IR.GetHigh32 (IR.To64 a b))",
"Filter": "",
- "Result": "(IR.Move32 b)"
+ "Result": "(IR.Move32 b)",
+ "Priority": "25"
},
{
"Type": "Simplification",
@@ -86,7 +92,8 @@
"SubName": "To64",
"Expression": "IR.GetHigh32 (IR.To64 a b)",
"Filter": "",
- "Result": "(IR.Move32 b)"
+ "Result": "(IR.Move32 b)",
+ "Priority": "25"
},
{
"Type": "Simplification",
@@ -94,7 +101,8 @@
"SubName": "To64",
"Expression": "IR.GetLow32 (IR.To64 a b)",
"Filter": "",
- "Result": "(IR.Move32 a)"
+ "Result": "(IR.Move32 a)",
+ "Priority": "25"
},
{
"Type": "Simplification",
diff --git a/Source/Mosa.Compiler.Framework/BaseTransform.cs b/Source/Mosa.Compiler.Framework/BaseTransform.cs
index fb3fc03215..9ca6ca1290 100644
--- a/Source/Mosa.Compiler.Framework/BaseTransform.cs
+++ b/Source/Mosa.Compiler.Framework/BaseTransform.cs
@@ -860,6 +860,271 @@ protected static bool IsBitValueSignBitCleared64(Operand operand1)
return operand1.BitValue.IsSignBitClear64;
}
+ protected static bool? EvaluateCompare(Operand operand1, Operand operand2, ConditionCode condition)
+ {
+ return EvaluateCompare(operand1.BitValue, operand2.BitValue, condition);
+ }
+
+ protected static bool? EvaluateCompare(BitValue value1, BitValue value2, ConditionCode condition)
+ {
+ switch (condition)
+ {
+ case ConditionCode.Equal:
+ if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown)
+ {
+ return value1.BitsSet == value2.BitsSet;
+ }
+ else if (value1.MaxValue == value1.MinValue && value1.MaxValue == value2.MaxValue && value1.MinValue == value2.MinValue)
+ {
+ return true;
+ }
+ else if (((value1.BitsSet & value2.BitsSet) != value1.BitsSet || (value1.BitsClear & value2.BitsClear) != value1.BitsClear) && !value1.AreAnyBitsKnown && !value2.AreAnyBitsKnown)
+ {
+ return false;
+ }
+ else if ((value1.BitsSet & value2.BitsClear) != 0 || (value2.BitsSet & value1.BitsClear) != 0)
+ {
+ return false;
+ }
+ else if (value1.MaxValue < value2.MinValue)
+ {
+ return false;
+ }
+ else if (value1.MinValue > value2.MaxValue)
+ {
+ return false;
+ }
+ break;
+
+ case ConditionCode.NotEqual:
+ if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown)
+ {
+ return value1.BitsSet != value2.BitsSet;
+ }
+ else if (value1.MaxValue == value1.MinValue && value1.MaxValue == value2.MaxValue && value1.MinValue == value2.MinValue)
+ {
+ return false;
+ }
+ else if (value1.AreAll64BitsKnown && value1.MaxValue == 0 && value2.BitsSet != 0)
+ {
+ return true;
+ }
+ else if (value2.AreAll64BitsKnown && value2.MaxValue == 0 && value1.BitsSet != 0)
+ {
+ return true;
+ }
+ else if ((value1.BitsSet & value2.BitsClear) != 0 || (value2.BitsSet & value1.BitsClear) != 0)
+ {
+ return true;
+ }
+ else if (value1.MaxValue < value2.MinValue)
+ {
+ return true;
+ }
+ else if (value1.MinValue > value2.MaxValue)
+ {
+ return true;
+ }
+ break;
+
+ case ConditionCode.UnsignedGreater:
+ if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown)
+ {
+ return value1.BitsSet > value2.BitsSet;
+ }
+ else if (value2.AreAll64BitsKnown && value2.MaxValue == 0 && value1.BitsSet != 0)
+ {
+ return true;
+ }
+ else if (value1.MinValue > value2.MaxValue)
+ {
+ return true;
+ }
+ else if (value1.MaxValue <= value2.MinValue)
+ {
+ return false;
+ }
+ break;
+
+ case ConditionCode.UnsignedLess:
+ if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown)
+ {
+ return value1.MaxValue < value2.MaxValue;
+ }
+ else if (value1.AreAll64BitsKnown && value1.MaxValue == 0 && value2.BitsSet != 0)
+ {
+ return true;
+ }
+ else if (value2.MinValue > value1.MaxValue)
+ {
+ return true;
+ }
+ else if (value2.MaxValue <= value1.MinValue)
+ {
+ return false;
+ }
+
+ break;
+
+ case ConditionCode.UnsignedGreaterOrEqual:
+ if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown)
+ {
+ return value1.BitsSet <= value2.BitsSet;
+ }
+ else if (value1.AreAll64BitsKnown && value1.MaxValue == 0 && value2.BitsSet != 0)
+ {
+ return true;
+ }
+ else if (value1.MinValue >= value2.MaxValue)
+ {
+ return true;
+ }
+ else if (value1.MaxValue < value2.MinValue)
+ {
+ return false;
+ }
+
+ break;
+
+ case ConditionCode.UnsignedLessOrEqual:
+ if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown)
+ {
+ return value1.BitsSet <= value2.BitsSet;
+ }
+ else if (value1.AreAll64BitsKnown && value1.MaxValue == 0 && value2.BitsSet != 0)
+ {
+ return true;
+ }
+ else if (value2.MinValue >= value1.MaxValue)
+ {
+ return true;
+ }
+ else if (value2.MaxValue < value1.MinValue)
+ {
+ return false;
+ }
+
+ break;
+
+ case ConditionCode.Greater:
+ if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown && value1.Is64Bit && value2.Is64Bit)
+ {
+ return (long)value1.BitsSet > (long)value2.BitsSet;
+ }
+ else if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown && value1.Is32Bit && value2.Is32Bit)
+ {
+ return (int)value1.BitsSet > (int)value2.BitsSet;
+ }
+ else if (value1.Is32Bit && value2.Is32Bit && value1.IsSignBitClear32 && value2.IsSignBitClear32 && value1.MinValue > value2.MaxValue)
+ {
+ return true;
+ }
+ else if (value1.Is32Bit && value2.Is32Bit && value1.IsSignBitClear32 && value2.IsSignBitClear32 && value1.MaxValue < value2.MinValue)
+ {
+ return false;
+ }
+ else if (value1.Is64Bit && value2.Is64Bit && value1.IsSignBitClear64 && value2.IsSignBitClear64 && value1.MinValue > value2.MaxValue)
+ {
+ return true;
+ }
+ else if (value1.Is64Bit && value2.Is64Bit && value1.IsSignBitClear64 && value2.IsSignBitClear64 && value1.MaxValue < value2.MinValue)
+ {
+ return false;
+ }
+
+ break;
+
+ case ConditionCode.Less:
+ if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown && value1.Is64Bit && value2.Is64Bit)
+ {
+ return (long)value1.BitsSet < (long)value2.BitsSet;
+ }
+ else if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown && value1.Is32Bit && value2.Is32Bit)
+ {
+ return (int)value1.BitsSet < (int)value2.BitsSet;
+ }
+ else if (value1.Is32Bit && value2.Is32Bit && value1.IsSignBitClear32 && value2.IsSignBitClear32 && value1.MaxValue < value2.MinValue)
+ {
+ return true;
+ }
+ else if (value1.Is32Bit && value2.Is32Bit && value1.IsSignBitClear32 && value2.IsSignBitClear32 && value1.MinValue > value2.MaxValue)
+ {
+ return false;
+ }
+ else if (value1.Is64Bit && value2.Is64Bit && value1.IsSignBitClear64 && value2.IsSignBitClear64 && value1.MaxValue < value2.MinValue)
+ {
+ return true;
+ }
+ else if (value1.Is64Bit && value2.Is64Bit && value1.IsSignBitClear64 && value2.IsSignBitClear64 && value1.MinValue > value2.MaxValue)
+ {
+ return false;
+ }
+
+ break;
+
+ case ConditionCode.GreaterOrEqual:
+ if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown && value1.Is64Bit && value2.Is64Bit)
+ {
+ return (long)value1.BitsSet >= (long)value2.BitsSet;
+ }
+ else if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown && value1.Is32Bit && value2.Is32Bit)
+ {
+ return (int)value1.BitsSet >= (int)value2.BitsSet;
+ }
+ else if (value1.Is32Bit && value2.Is32Bit && value1.IsSignBitClear32 && value2.IsSignBitClear32 && value1.MinValue >= value2.MaxValue)
+ {
+ return true;
+ }
+ else if (value1.Is32Bit && value2.Is32Bit && value1.IsSignBitClear32 && value2.IsSignBitClear32 && value1.MaxValue <= value2.MinValue)
+ {
+ return false;
+ }
+ else if (value1.Is64Bit && value2.Is64Bit && value1.IsSignBitClear64 && value2.IsSignBitClear64 && value1.MinValue >= value2.MaxValue)
+ {
+ return true;
+ }
+ else if (value1.Is64Bit && value2.Is64Bit && value1.IsSignBitClear64 && value2.IsSignBitClear64 && value1.MaxValue <= value2.MinValue)
+ {
+ return false;
+ }
+
+ break;
+
+ case ConditionCode.LessOrEqual:
+ if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown && value1.Is64Bit && value2.Is64Bit)
+ {
+ return (long)value1.BitsSet <= (long)value2.BitsSet;
+ }
+ else if (value1.AreAll64BitsKnown && value2.AreAll64BitsKnown && value1.Is32Bit && value2.Is32Bit)
+ {
+ return (int)value1.BitsSet <= (int)value2.BitsSet;
+ }
+ else if (value1.Is32Bit && value2.Is32Bit && value1.IsSignBitClear32 && value2.IsSignBitClear32 && value1.MaxValue <= value2.MinValue)
+ {
+ return true;
+ }
+ else if (value1.Is32Bit && value2.Is32Bit && value1.IsSignBitClear32 && value2.IsSignBitClear32 && value1.MinValue >= value2.MaxValue)
+ {
+ return false;
+ }
+ else if (value1.Is64Bit && value2.Is64Bit && value1.IsSignBitClear64 && value2.IsSignBitClear64 && value1.MaxValue <= value2.MinValue)
+ {
+ return true;
+ }
+ else if (value1.Is64Bit && value2.Is64Bit && value1.IsSignBitClear64 && value2.IsSignBitClear64 && value1.MinValue >= value2.MaxValue)
+ {
+ return false;
+ }
+
+ break;
+
+ default:
+ return null;
+ }
+
+ return null;
+ }
+
#endregion BitTracker Helpers
#region Navigation
diff --git a/Source/Mosa.Compiler.Framework/BitValueStage.cs b/Source/Mosa.Compiler.Framework/BitValueStage.cs
deleted file mode 100644
index 54df047c11..0000000000
--- a/Source/Mosa.Compiler.Framework/BitValueStage.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (c) MOSA Project. Licensed under the New BSD License.
-
-namespace Mosa.Compiler.Framework;
-
-public enum BitValueStage
-{
- Initial,
- Partial,
- Stable
-};
diff --git a/Source/Mosa.Compiler.Framework/Transform.cs b/Source/Mosa.Compiler.Framework/Transform.cs
index fe6a165d14..86bcf7016b 100644
--- a/Source/Mosa.Compiler.Framework/Transform.cs
+++ b/Source/Mosa.Compiler.Framework/Transform.cs
@@ -2,7 +2,6 @@
using System.Diagnostics;
using Mosa.Compiler.Framework.Linker;
-using Mosa.Compiler.Framework.Managers;
using Mosa.Compiler.MosaTypeSystem;
namespace Mosa.Compiler.Framework;
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/ArithShiftRight32NotSigned.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/ArithShiftRight32NotSigned.cs
index f685a62838..2962431563 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/ArithShiftRight32NotSigned.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/ArithShiftRight32NotSigned.cs
@@ -10,7 +10,7 @@ namespace Mosa.Compiler.Framework.Transforms.Optimizations.Auto.BitValue;
[Transform("IR.Optimizations.Auto.BitValue")]
public sealed class ArithShiftRight32NotSigned : BaseTransform
{
- public ArithShiftRight32NotSigned() : base(IRInstruction.ArithShiftRight32, TransformType.Auto | TransformType.Optimization, true)
+ public ArithShiftRight32NotSigned() : base(IRInstruction.ArithShiftRight32, TransformType.Auto | TransformType.Optimization)
{
}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/ArithShiftRight64NotSigned.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/ArithShiftRight64NotSigned.cs
index d0ff661d5f..e6c8552e11 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/ArithShiftRight64NotSigned.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/ArithShiftRight64NotSigned.cs
@@ -10,7 +10,7 @@ namespace Mosa.Compiler.Framework.Transforms.Optimizations.Auto.BitValue;
[Transform("IR.Optimizations.Auto.BitValue")]
public sealed class ArithShiftRight64NotSigned : BaseTransform
{
- public ArithShiftRight64NotSigned() : base(IRInstruction.ArithShiftRight64, TransformType.Auto | TransformType.Optimization, true)
+ public ArithShiftRight64NotSigned() : base(IRInstruction.ArithShiftRight64, TransformType.Auto | TransformType.Optimization)
{
}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/MulSigned32NotSigned.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/MulSigned32NotSigned.cs
index 72f2874dc5..3b86384b1a 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/MulSigned32NotSigned.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/MulSigned32NotSigned.cs
@@ -10,7 +10,7 @@ namespace Mosa.Compiler.Framework.Transforms.Optimizations.Auto.BitValue;
[Transform("IR.Optimizations.Auto.BitValue")]
public sealed class MulSigned32NotSigned : BaseTransform
{
- public MulSigned32NotSigned() : base(IRInstruction.MulSigned32, TransformType.Auto | TransformType.Optimization, true)
+ public MulSigned32NotSigned() : base(IRInstruction.MulSigned32, TransformType.Auto | TransformType.Optimization)
{
}
@@ -44,7 +44,7 @@ public override void Transform(Context context, Transform transform)
[Transform("IR.Optimizations.Auto.BitValue")]
public sealed class MulSigned32NotSigned_v1 : BaseTransform
{
- public MulSigned32NotSigned_v1() : base(IRInstruction.MulSigned32, TransformType.Auto | TransformType.Optimization, true)
+ public MulSigned32NotSigned_v1() : base(IRInstruction.MulSigned32, TransformType.Auto | TransformType.Optimization)
{
}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/MulSigned64NotSigned.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/MulSigned64NotSigned.cs
index bb7427e740..e76fe2643d 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/MulSigned64NotSigned.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/MulSigned64NotSigned.cs
@@ -10,7 +10,7 @@ namespace Mosa.Compiler.Framework.Transforms.Optimizations.Auto.BitValue;
[Transform("IR.Optimizations.Auto.BitValue")]
public sealed class MulSigned64NotSigned : BaseTransform
{
- public MulSigned64NotSigned() : base(IRInstruction.MulSigned64, TransformType.Auto | TransformType.Optimization, true)
+ public MulSigned64NotSigned() : base(IRInstruction.MulSigned64, TransformType.Auto | TransformType.Optimization)
{
}
@@ -44,7 +44,7 @@ public override void Transform(Context context, Transform transform)
[Transform("IR.Optimizations.Auto.BitValue")]
public sealed class MulSigned64NotSigned_v1 : BaseTransform
{
- public MulSigned64NotSigned_v1() : base(IRInstruction.MulSigned64, TransformType.Auto | TransformType.Optimization, true)
+ public MulSigned64NotSigned_v1() : base(IRInstruction.MulSigned64, TransformType.Auto | TransformType.Optimization)
{
}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/RemSigned32NotSigned.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/RemSigned32NotSigned.cs
index 4165243265..ddb6718f8d 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/RemSigned32NotSigned.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/RemSigned32NotSigned.cs
@@ -10,7 +10,7 @@ namespace Mosa.Compiler.Framework.Transforms.Optimizations.Auto.BitValue;
[Transform("IR.Optimizations.Auto.BitValue")]
public sealed class RemSigned32NotSigned : BaseTransform
{
- public RemSigned32NotSigned() : base(IRInstruction.RemSigned32, TransformType.Auto | TransformType.Optimization, true)
+ public RemSigned32NotSigned() : base(IRInstruction.RemSigned32, TransformType.Auto | TransformType.Optimization)
{
}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/RemSigned64NotSigned.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/RemSigned64NotSigned.cs
index cf5662d160..536a1a26a1 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/RemSigned64NotSigned.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/BitValue/RemSigned64NotSigned.cs
@@ -10,7 +10,7 @@ namespace Mosa.Compiler.Framework.Transforms.Optimizations.Auto.BitValue;
[Transform("IR.Optimizations.Auto.BitValue")]
public sealed class RemSigned64NotSigned : BaseTransform
{
- public RemSigned64NotSigned() : base(IRInstruction.RemSigned64, TransformType.Auto | TransformType.Optimization, true)
+ public RemSigned64NotSigned() : base(IRInstruction.RemSigned64, TransformType.Auto | TransformType.Optimization)
{
}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetHigh32FromTo64.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetHigh32FromTo64.cs
index db6f4ee692..53ddb0150e 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetHigh32FromTo64.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetHigh32FromTo64.cs
@@ -14,6 +14,8 @@ public GetHigh32FromTo64() : base(IRInstruction.GetHigh32, TransformType.Auto |
{
}
+ public override int Priority => 25;
+
public override bool Match(Context context, Transform transform)
{
if (!context.Operand1.IsVirtualRegister)
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetHigh32To64.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetHigh32To64.cs
index 4c34f5c6d3..f696fed2ab 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetHigh32To64.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetHigh32To64.cs
@@ -14,6 +14,8 @@ public GetHigh32To64() : base(IRInstruction.GetHigh32, TransformType.Auto | Tran
{
}
+ public override int Priority => 25;
+
public override bool Match(Context context, Transform transform)
{
if (!context.Operand1.IsVirtualRegister)
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetLow32FromTo64.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetLow32FromTo64.cs
index 5aed8817c9..9c3af50717 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetLow32FromTo64.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetLow32FromTo64.cs
@@ -14,6 +14,8 @@ public GetLow32FromTo64() : base(IRInstruction.GetLow32, TransformType.Auto | Tr
{
}
+ public override int Priority => 25;
+
public override bool Match(Context context, Transform transform)
{
if (!context.Operand1.IsVirtualRegister)
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetLow32To64.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetLow32To64.cs
index 51d45c80d0..23f37d3aa3 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetLow32To64.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/GetLow32To64.cs
@@ -14,6 +14,8 @@ public GetLow32To64() : base(IRInstruction.GetLow32, TransformType.Auto | Transf
{
}
+ public override int Priority => 25;
+
public override bool Match(Context context, Transform transform)
{
if (!context.Operand1.IsVirtualRegister)
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Move32Coalescing.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Move32Coalescing.cs
index 2320e74016..223f3c0ddd 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Move32Coalescing.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Move32Coalescing.cs
@@ -14,6 +14,8 @@ public Move32Coalescing() : base(IRInstruction.Move32, TransformType.Auto | Tran
{
}
+ public override int Priority => 25;
+
public override bool Match(Context context, Transform transform)
{
if (!context.Operand1.IsVirtualRegister)
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Move64Coalescing.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Move64Coalescing.cs
index bd22376c8c..85875cd06a 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Move64Coalescing.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Move64Coalescing.cs
@@ -14,6 +14,8 @@ public Move64Coalescing() : base(IRInstruction.Move64, TransformType.Auto | Tran
{
}
+ public override int Priority => 25;
+
public override bool Match(Context context, Transform transform)
{
if (!context.Operand1.IsVirtualRegister)
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/MoveManagedPointerCoalescing.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/MoveManagedPointerCoalescing.cs
index cd078e0899..89ed8874b1 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/MoveManagedPointerCoalescing.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/MoveManagedPointerCoalescing.cs
@@ -14,6 +14,8 @@ public MoveManagedPointerCoalescing() : base(IRInstruction.MoveManagedPointer, T
{
}
+ public override int Priority => 25;
+
public override bool Match(Context context, Transform transform)
{
if (!context.Operand1.IsVirtualRegister)
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/MoveObjectCoalescing.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/MoveObjectCoalescing.cs
index e592b2be82..bf41522cc1 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/MoveObjectCoalescing.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/MoveObjectCoalescing.cs
@@ -14,6 +14,8 @@ public MoveObjectCoalescing() : base(IRInstruction.MoveObject, TransformType.Aut
{
}
+ public override int Priority => 25;
+
public override bool Match(Context context, Transform transform)
{
if (!context.Operand1.IsVirtualRegister)
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Not32Twice.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Not32Twice.cs
index 170fa63eb3..652c49d607 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Not32Twice.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Not32Twice.cs
@@ -14,6 +14,8 @@ public Not32Twice() : base(IRInstruction.Not32, TransformType.Auto | TransformTy
{
}
+ public override int Priority => 25;
+
public override bool Match(Context context, Transform transform)
{
if (!context.Operand1.IsVirtualRegister)
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Not64Twice.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Not64Twice.cs
index 56a770f252..0c132740a5 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Not64Twice.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Auto/Simplification/Not64Twice.cs
@@ -14,6 +14,8 @@ public Not64Twice() : base(IRInstruction.Not64, TransformType.Auto | TransformTy
{
}
+ public override int Priority => 25;
+
public override bool Match(Context context, Transform transform)
{
if (!context.Operand1.IsVirtualRegister)
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Branch32.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Branch32.cs
new file mode 100644
index 0000000000..a201229fd7
--- /dev/null
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Branch32.cs
@@ -0,0 +1,50 @@
+// Copyright (c) MOSA Project. Licensed under the New BSD License.
+
+namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.BitValue;
+
+public sealed class Branch32 : BaseTransform
+{
+ public Branch32() : base(IRInstruction.Branch32, TransformType.Manual | TransformType.Optimization, true)
+ {
+ }
+
+ public override int Priority => 100;
+
+ public override bool Match(Context context, Transform transform)
+ {
+ if (context.Block.NextBlocks.Count == 1)
+ return false;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ if (!value.HasValue)
+ return false;
+
+ return true;
+ }
+
+ public override void Transform(Context context, Transform transform)
+ {
+ var target = context.BranchTargets[0];
+ var block = context.Block;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ if (!value.Value)
+ {
+ context.SetNop();
+
+ Framework.Transform.UpdatePhiBlock(target);
+ }
+ else
+ {
+ var phiBlock = GetOtherBranchTarget(block, target);
+
+ context.SetInstruction(IRInstruction.Jmp, target);
+
+ RemoveRemainingInstructionInBlock(context);
+
+ Framework.Transform.UpdatePhiBlock(phiBlock);
+ }
+ }
+}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Branch64.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Branch64.cs
new file mode 100644
index 0000000000..6d499c18e3
--- /dev/null
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Branch64.cs
@@ -0,0 +1,50 @@
+// Copyright (c) MOSA Project. Licensed under the New BSD License.
+
+namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.BitValue;
+
+public sealed class Branch64 : BaseTransform
+{
+ public Branch64() : base(IRInstruction.Branch64, TransformType.Manual | TransformType.Optimization)
+ {
+ }
+
+ public override int Priority => 100;
+
+ public override bool Match(Context context, Transform transform)
+ {
+ if (context.Block.NextBlocks.Count == 1)
+ return false;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ if (!value.HasValue)
+ return false;
+
+ return true;
+ }
+
+ public override void Transform(Context context, Transform transform)
+ {
+ var target = context.BranchTargets[0];
+ var block = context.Block;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ if (!value.Value)
+ {
+ context.SetNop();
+
+ Framework.Transform.UpdatePhiBlock(target);
+ }
+ else
+ {
+ var phiBlock = GetOtherBranchTarget(block, target);
+
+ context.SetInstruction(IRInstruction.Jmp, target);
+
+ RemoveRemainingInstructionInBlock(context);
+
+ Framework.Transform.UpdatePhiBlock(phiBlock);
+ }
+ }
+}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/BranchManagedPointer.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/BranchManagedPointer.cs
new file mode 100644
index 0000000000..3166c0d1b2
--- /dev/null
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/BranchManagedPointer.cs
@@ -0,0 +1,50 @@
+// Copyright (c) MOSA Project. Licensed under the New BSD License.
+
+namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.BitValue;
+
+public sealed class BranchManagedPointer : BaseTransform
+{
+ public BranchManagedPointer() : base(IRInstruction.BranchManagedPointer, TransformType.Manual | TransformType.Optimization)
+ {
+ }
+
+ public override int Priority => 100;
+
+ public override bool Match(Context context, Transform transform)
+ {
+ if (context.Block.NextBlocks.Count == 1)
+ return false;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ if (!value.HasValue)
+ return false;
+
+ return true;
+ }
+
+ public override void Transform(Context context, Transform transform)
+ {
+ var target = context.BranchTargets[0];
+ var block = context.Block;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ if (!value.Value)
+ {
+ context.SetNop();
+
+ Framework.Transform.UpdatePhiBlock(target);
+ }
+ else
+ {
+ var phiBlock = GetOtherBranchTarget(block, target);
+
+ context.SetInstruction(IRInstruction.Jmp, target);
+
+ RemoveRemainingInstructionInBlock(context);
+
+ Framework.Transform.UpdatePhiBlock(phiBlock);
+ }
+ }
+}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/BranchObject.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/BranchObject.cs
new file mode 100644
index 0000000000..2dda755692
--- /dev/null
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/BranchObject.cs
@@ -0,0 +1,50 @@
+// Copyright (c) MOSA Project. Licensed under the New BSD License.
+
+namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.BitValue;
+
+public sealed class BranchObject : BaseTransform
+{
+ public BranchObject() : base(IRInstruction.BranchObject, TransformType.Manual | TransformType.Optimization)
+ {
+ }
+
+ public override int Priority => 100;
+
+ public override bool Match(Context context, Transform transform)
+ {
+ if (context.Block.NextBlocks.Count == 1)
+ return false;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ if (!value.HasValue)
+ return false;
+
+ return true;
+ }
+
+ public override void Transform(Context context, Transform transform)
+ {
+ var target = context.BranchTargets[0];
+ var block = context.Block;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ if (!value.Value)
+ {
+ context.SetNop();
+
+ Framework.Transform.UpdatePhiBlock(target);
+ }
+ else
+ {
+ var phiBlock = GetOtherBranchTarget(block, target);
+
+ context.SetInstruction(IRInstruction.Jmp, target);
+
+ RemoveRemainingInstructionInBlock(context);
+
+ Framework.Transform.UpdatePhiBlock(phiBlock);
+ }
+ }
+}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Compare32x32BitValue.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Compare32x32BitValue.cs
new file mode 100644
index 0000000000..02d8eb95af
--- /dev/null
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Compare32x32BitValue.cs
@@ -0,0 +1,37 @@
+// Copyright (c) MOSA Project. Licensed under the New BSD License.
+
+namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.BitValue;
+
+///
+/// Compare32x32BitValue
+///
+[Transform("IR.Optimizations.Manual.BitVaule")]
+public sealed class Compare32x32BitValue : BaseTransform
+{
+ public Compare32x32BitValue() : base(IRInstruction.Compare32x32, TransformType.Manual | TransformType.Optimization, true)
+ {
+ }
+
+ public override int Priority => 35;
+
+ public override bool Match(Context context, Transform transform)
+ {
+ if (!context.Result.IsDefinedOnce)
+ return false;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ return value.HasValue;
+ }
+
+ public override void Transform(Context context, Transform transform)
+ {
+ var result = context.Result;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ var constant = Operand.CreateConstant32(value.Value ? 1 : 0);
+
+ context.SetInstruction(IRInstruction.Move32, result, constant);
+ }
+}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Compare32x64BitValue.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Compare32x64BitValue.cs
new file mode 100644
index 0000000000..a3b78c49ad
--- /dev/null
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Compare32x64BitValue.cs
@@ -0,0 +1,37 @@
+// Copyright (c) MOSA Project. Licensed under the New BSD License.
+
+namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.BitValue;
+
+///
+/// Compare32x64BitValue
+///
+[Transform("IR.Optimizations.Manual.BitVaule")]
+public sealed class Compare32x64BitValue : BaseTransform
+{
+ public Compare32x64BitValue() : base(IRInstruction.Compare32x64, TransformType.Manual | TransformType.Optimization, true)
+ {
+ }
+
+ public override int Priority => 35;
+
+ public override bool Match(Context context, Transform transform)
+ {
+ if (!context.Result.IsDefinedOnce)
+ return false;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ return value.HasValue;
+ }
+
+ public override void Transform(Context context, Transform transform)
+ {
+ var result = context.Result;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ var constant = Operand.CreateConstant64(value.Value ? 1 : 0);
+
+ context.SetInstruction(IRInstruction.Move64, result, constant);
+ }
+}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Compare64x32BitValue.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Compare64x32BitValue.cs
new file mode 100644
index 0000000000..c1a831f97c
--- /dev/null
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Compare64x32BitValue.cs
@@ -0,0 +1,37 @@
+// Copyright (c) MOSA Project. Licensed under the New BSD License.
+
+namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.BitValue;
+
+///
+/// Compare64x32BitValue
+///
+[Transform("IR.Optimizations.Manual.BitVaule")]
+public sealed class Compare64x32BitValue : BaseTransform
+{
+ public Compare64x32BitValue() : base(IRInstruction.Compare64x32, TransformType.Manual | TransformType.Optimization, true)
+ {
+ }
+
+ public override int Priority => 35;
+
+ public override bool Match(Context context, Transform transform)
+ {
+ if (!context.Result.IsDefinedOnce)
+ return false;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ return value.HasValue;
+ }
+
+ public override void Transform(Context context, Transform transform)
+ {
+ var result = context.Result;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ var constant = Operand.CreateConstant32(value.Value ? 1 : 0);
+
+ context.SetInstruction(IRInstruction.Move32, result, constant);
+ }
+}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Compare64x64BitValue.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Compare64x64BitValue.cs
new file mode 100644
index 0000000000..7d55673310
--- /dev/null
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/BitValue/Compare64x64BitValue.cs
@@ -0,0 +1,37 @@
+// Copyright (c) MOSA Project. Licensed under the New BSD License.
+
+namespace Mosa.Compiler.Framework.Transforms.Optimizations.Manual.BitValue;
+
+///
+/// Compare32x32BitValue
+///
+[Transform("IR.Optimizations.Manual.BitVaule")]
+public sealed class Compare64x64BitValue : BaseTransform
+{
+ public Compare64x64BitValue() : base(IRInstruction.Compare64x64, TransformType.Manual | TransformType.Optimization, true)
+ {
+ }
+
+ public override int Priority => 35;
+
+ public override bool Match(Context context, Transform transform)
+ {
+ if (!context.Result.IsDefinedOnce)
+ return false;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ return value.HasValue;
+ }
+
+ public override void Transform(Context context, Transform transform)
+ {
+ var result = context.Result;
+
+ var value = EvaluateCompare(context.Operand1, context.Operand2, context.ConditionCode);
+
+ var constant = Operand.CreateConstant64(value.Value ? 1 : 0);
+
+ context.SetInstruction(IRInstruction.Move64, result, constant);
+ }
+}
diff --git a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/ManualTransforms.cs b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/ManualTransforms.cs
index 2813c1a385..c028f9d5f5 100644
--- a/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/ManualTransforms.cs
+++ b/Source/Mosa.Compiler.Framework/Transforms/Optimizations/Manual/ManualTransforms.cs
@@ -309,5 +309,15 @@ public static class ManualTransforms
new Phi.PhiObjectUpdate(),
new Phi.PhiManagedPointerDead(),
new Phi.PhiManagedPointerUpdate(),
+
+ new BitValue.Compare32x32BitValue(),
+ new BitValue.Compare32x64BitValue(),
+ new BitValue.Compare64x32BitValue(),
+ new BitValue.Compare64x64BitValue(),
+
+ new BitValue.Branch32(),
+ new BitValue.Branch64(),
+ new BitValue.BranchManagedPointer(),
+ new BitValue.BranchObject(),
};
}