From ae878ad7deaff16a6fcac3ab7b170e1df8734066 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Mon, 15 Jan 2024 20:21:16 -0800 Subject: [PATCH 1/3] Consume regs for BlkOpKindLoop --- src/coreclr/jit/codegenarmarch.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/codegenarmarch.cpp b/src/coreclr/jit/codegenarmarch.cpp index cb04cf702f2b94..41a81aac4952fe 100644 --- a/src/coreclr/jit/codegenarmarch.cpp +++ b/src/coreclr/jit/codegenarmarch.cpp @@ -3257,12 +3257,13 @@ void CodeGen::genCodeForInitBlkLoop(GenTreeBlk* initBlkNode) genConsumeReg(dstNode); const regNumber dstReg = dstNode->GetRegNum(); -#ifndef TARGET_ARM64 GenTree* const zeroNode = initBlkNode->Data(); genConsumeReg(zeroNode); - const regNumber zeroReg = zeroNode->GetRegNum(); -#else + +#ifdef TARGET_ARM64 const regNumber zeroReg = REG_ZR; +#else + const regNumber zeroReg = zeroNode->GetRegNum(); #endif if (initBlkNode->IsVolatile()) From 8e46706bebfccc9b0fd3d6d760907fc988b9d0cb Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Tue, 16 Jan 2024 07:15:44 -0800 Subject: [PATCH 2/3] Mark the node as contained --- src/coreclr/jit/codegenarmarch.cpp | 7 +- src/coreclr/jit/lowerarmarch.cpp | 5 + .../tools/aot/ILCompiler/repro/Program.cs | 115 +++++++++++++++++- 3 files changed, 122 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/codegenarmarch.cpp b/src/coreclr/jit/codegenarmarch.cpp index 41a81aac4952fe..cb04cf702f2b94 100644 --- a/src/coreclr/jit/codegenarmarch.cpp +++ b/src/coreclr/jit/codegenarmarch.cpp @@ -3257,13 +3257,12 @@ void CodeGen::genCodeForInitBlkLoop(GenTreeBlk* initBlkNode) genConsumeReg(dstNode); const regNumber dstReg = dstNode->GetRegNum(); +#ifndef TARGET_ARM64 GenTree* const zeroNode = initBlkNode->Data(); genConsumeReg(zeroNode); - -#ifdef TARGET_ARM64 - const regNumber zeroReg = REG_ZR; -#else const regNumber zeroReg = zeroNode->GetRegNum(); +#else + const regNumber zeroReg = REG_ZR; #endif if (initBlkNode->IsVolatile()) diff --git a/src/coreclr/jit/lowerarmarch.cpp b/src/coreclr/jit/lowerarmarch.cpp index 20eea0e31e7a22..369cde21a386f0 100644 --- a/src/coreclr/jit/lowerarmarch.cpp +++ b/src/coreclr/jit/lowerarmarch.cpp @@ -570,6 +570,11 @@ void Lowering::LowerBlockStore(GenTreeBlk* blkNode) ((blkNode->GetLayout()->GetSize() % TARGET_POINTER_SIZE) == 0) && src->IsIntegralConst(0)) { blkNode->gtBlkOpKind = GenTreeBlk::BlkOpKindLoop; +#ifdef TARGET_ARM64 + // On ARM64 we can just use REG_ZR instead of having to load + // the constant into a real register like on ARM32. + src->SetContained(); +#endif return; } #endif diff --git a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs index 9e71394c3732a5..6390d196397af6 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs @@ -1,12 +1,125 @@ +//i = 9; // 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.Runtime.CompilerServices; + +public class A { [ThreadStatic] public static string a; } +public class B { public static string s = "a"; } class Program { + //[ThreadStatic] + //static string i = 5.ToString(); + ////[ThreadStatic] + //static string j = 10.ToString(); + //[ThreadStatic] // problematic + //static string k = 5.ToString(); + + //static int l = GetInt(); + [ThreadStatic] static int m = 6; + [ThreadStatic] static int n = 5; + + //[MethodImpl(MethodImplOptions.NoInlining)] + //private static int GetInt() => 1; + + //[ThreadStatic] + //static string j = 5.ToString(); + //static Program() + //{ + // i = 6; + //} static void Main() { - Console.WriteLine("Hello world"); + Test1(); + Test2(); + //A.a = "a"; + //i = 9; + //Consume(A.a, i); + + //i = 9; + //j = 10; + //for (int k = 0; k < 10; k++) + { + //Consume(j); + //for (int _i = 0;_i < 10; _i++) + //{ + // Test(); + // //Consume(i); + // //Consume(n); + + // //Consume(j); + + // //Consume(l); + //Consume(n); + + // //Consume(l); + // //Consume(m); + + + //} + + //Consume(j); + //Consume(k); + + //Consume(A.a); + //Consume(j); + } + //Consume(k); + + //Consume(A.a, B.s); + + //A.a = "a"; + //Consume(A.a); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static void Test1() + { + Consume(m); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static void Test2() + { + Consume(n); } + + [MethodImpl(MethodImplOptions.NoInlining)] + static void Consume(string a) + { + Console.WriteLine("here" + a); + //i = 5; + //Consume(i); + //i = "a"; + //j = "a"; + Consume("i", "j"); + //Consume(i, j); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static void Consume(int a) + { + + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static void Consume(string a, string b) + { + + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static void Consume(string a, int b) + { + + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static int Produce() + { + return 1; + } + } From 06c89ee7e0783ce3a81107851f95c37d3013e297 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Tue, 16 Jan 2024 07:17:18 -0800 Subject: [PATCH 3/3] undo Program.cs commit --- .../tools/aot/ILCompiler/repro/Program.cs | 115 +----------------- 1 file changed, 1 insertion(+), 114 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs index 6390d196397af6..9e71394c3732a5 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs @@ -1,125 +1,12 @@ -//i = 9; // 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.Runtime.CompilerServices; - -public class A { [ThreadStatic] public static string a; } -public class B { public static string s = "a"; } class Program { - //[ThreadStatic] - //static string i = 5.ToString(); - ////[ThreadStatic] - //static string j = 10.ToString(); - //[ThreadStatic] // problematic - //static string k = 5.ToString(); - - //static int l = GetInt(); - [ThreadStatic] static int m = 6; - [ThreadStatic] static int n = 5; - - //[MethodImpl(MethodImplOptions.NoInlining)] - //private static int GetInt() => 1; - - //[ThreadStatic] - //static string j = 5.ToString(); - //static Program() - //{ - // i = 6; - //} static void Main() { - Test1(); - Test2(); - //A.a = "a"; - //i = 9; - //Consume(A.a, i); - - //i = 9; - //j = 10; - //for (int k = 0; k < 10; k++) - { - //Consume(j); - //for (int _i = 0;_i < 10; _i++) - //{ - // Test(); - // //Consume(i); - // //Consume(n); - - // //Consume(j); - - // //Consume(l); - //Consume(n); - - // //Consume(l); - // //Consume(m); - - - //} - - //Consume(j); - //Consume(k); - - //Consume(A.a); - //Consume(j); - } - //Consume(k); - - //Consume(A.a, B.s); - - //A.a = "a"; - //Consume(A.a); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - static void Test1() - { - Consume(m); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - static void Test2() - { - Consume(n); + Console.WriteLine("Hello world"); } - - [MethodImpl(MethodImplOptions.NoInlining)] - static void Consume(string a) - { - Console.WriteLine("here" + a); - //i = 5; - //Consume(i); - //i = "a"; - //j = "a"; - Consume("i", "j"); - //Consume(i, j); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - static void Consume(int a) - { - - } - - [MethodImpl(MethodImplOptions.NoInlining)] - static void Consume(string a, string b) - { - - } - - [MethodImpl(MethodImplOptions.NoInlining)] - static void Consume(string a, int b) - { - - } - - [MethodImpl(MethodImplOptions.NoInlining)] - static int Produce() - { - return 1; - } - }