[JIT] X64 Fix - Handle 'imul' instruction variants to determine if a register was...
authorWill Smith <lol.tihan@gmail.com>
Tue, 2 May 2023 14:22:58 +0000 (07:22 -0700)
committerGitHub <noreply@github.com>
Tue, 2 May 2023 14:22:58 +0000 (07:22 -0700)
src/coreclr/jit/emitxarch.cpp
src/tests/JIT/Regression/JitBlue/Runtime_85602/Runtime_85602.cs [new file with mode: 0644]
src/tests/JIT/Regression/JitBlue/Runtime_85602/Runtime_85602.csproj [new file with mode: 0644]

index 5677952..2e382fa 100644 (file)
@@ -664,6 +664,30 @@ bool emitter::emitIsInstrWritingToReg(instrDesc* id, regNumber reg)
         case INS_call:
             return true;
 
+        case INS_imul_AX:
+        case INS_imul_BP:
+        case INS_imul_BX:
+        case INS_imul_CX:
+        case INS_imul_DI:
+        case INS_imul_DX:
+        case INS_imul_SI:
+        case INS_imul_SP:
+#ifdef TARGET_AMD64
+        case INS_imul_08:
+        case INS_imul_09:
+        case INS_imul_10:
+        case INS_imul_11:
+        case INS_imul_12:
+        case INS_imul_13:
+        case INS_imul_14:
+        case INS_imul_15:
+#endif // TARGET_AMD64
+            if (reg == inst3opImulReg(ins))
+            {
+                return true;
+            }
+            break;
+
         // These always write to RAX and RDX.
         case INS_idiv:
         case INS_div:
diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_85602/Runtime_85602.cs b/src/tests/JIT/Regression/JitBlue/Runtime_85602/Runtime_85602.cs
new file mode 100644 (file)
index 0000000..f594215
--- /dev/null
@@ -0,0 +1,50 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+public class Test
+{
+    public class C0
+    {
+        public C0(ulong f0, sbyte f1, byte f2, ulong f3, ulong f4, int f5, short f6)
+        {
+        }
+    }
+
+    // This is trying to verify that we eliminate 'mov' instructions correctly.
+    public class Program
+    {
+        [MethodImpl(MethodImplOptions.NoInlining)]
+        public static ulong Consume(ulong x) { return x; }
+
+        public static ushort s_1;
+
+        [MethodImpl(MethodImplOptions.NoInlining)]
+        public static ulong M0()
+        {
+            ulong var0 = ~(ulong)(uint)(-15356 * (2637600427U % (byte)((2147483647 ^ (4167361218894137384UL * (ushort)(-(ushort)(-(ushort)(128 * (5114990800133743712L % (byte)((byte)(-(byte)(-(byte)(-(byte)~(byte)(-2 % (short)((short)~(short)(-(short)(-90400400 - (-(0 | ~~(int)(32766 & (uint)(-~(uint)(-(uint)(629572031969723397L ^ (sbyte)(1UL * (byte)(8945663325738713761L / ((-(long)(127 / (sbyte)((sbyte)(-23817 % (ushort)((ushort)~M1(new C0(8144643251292930980UL, -118, 183, 18446744073709551614UL, 1827525571111008345UL, 1751590714, -32653)) | 1)) | 1))) | 1))))))))))) | 1))))) | 1))))))) | 1)));
+            return Program.Consume(var0);
+        }
+
+        public static ushort M1(C0 argThis)
+        {
+            return s_1;
+        }
+    }
+
+    [Fact]
+    public static int TestEntryPoint()
+    {
+        var result = Test.Program.M0();
+        if (result != 18446744069414922151)
+        {
+            return 0;
+        }
+        return 100;
+    }
+}
diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_85602/Runtime_85602.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_85602/Runtime_85602.csproj
new file mode 100644 (file)
index 0000000..15edd99
--- /dev/null
@@ -0,0 +1,8 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <Optimize>True</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="$(MSBuildProjectName).cs" />
+  </ItemGroup>
+</Project>
\ No newline at end of file