From 7639bb2e863fdd24876b7ef0993fcdc3bbda10a2 Mon Sep 17 00:00:00 2001
From: Ficture Seven <FICTURE7@gmail.com>
Date: Sat, 11 Jul 2020 04:35:38 +0400
Subject: [PATCH] Fold ConvertI64ToI32 imm64 (#1359)

* Fold ConvertI64ToI32 imm64

* Increment PTC version

* Bump PPTC InternalVersion

Co-authored-by: jduncanator <1518948+jduncanator@users.noreply.github.com>
---
 ARMeilleure/CodeGen/Optimizations/ConstantFolding.cs | 7 +++++++
 ARMeilleure/Translation/PTC/Ptc.cs                   | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ARMeilleure/CodeGen/Optimizations/ConstantFolding.cs b/ARMeilleure/CodeGen/Optimizations/ConstantFolding.cs
index 790fd53d00..359af113ce 100644
--- a/ARMeilleure/CodeGen/Optimizations/ConstantFolding.cs
+++ b/ARMeilleure/CodeGen/Optimizations/ConstantFolding.cs
@@ -78,6 +78,13 @@ namespace ARMeilleure.CodeGen.Optimizations
                     }
                     break;
 
+                case Instruction.ConvertI64ToI32:
+                    if (type == OperandType.I32)
+                    {
+                        EvaluateUnaryI64(operation, (x) => (int)x);
+                    }
+                    break;
+
                 case Instruction.Copy:
                     if (type == OperandType.I32)
                     {
diff --git a/ARMeilleure/Translation/PTC/Ptc.cs b/ARMeilleure/Translation/PTC/Ptc.cs
index c715160392..2742719dd2 100644
--- a/ARMeilleure/Translation/PTC/Ptc.cs
+++ b/ARMeilleure/Translation/PTC/Ptc.cs
@@ -20,7 +20,7 @@ namespace ARMeilleure.Translation.PTC
     {
         private const string HeaderMagic = "PTChd";
 
-        private const int InternalVersion = 3; //! To be incremented manually for each change to the ARMeilleure project.
+        private const int InternalVersion = 4; //! To be incremented manually for each change to the ARMeilleure project.
 
         private const string BaseDir = "Ryujinx";