From d0c588cec3c8e47e5f079dc8c6333a02b1bf46de Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Sun, 9 Mar 2025 12:58:33 +0200 Subject: [PATCH 1/6] Fix CAS mustExpand assertions in checked build --- src/coreclr/jit/importercalls.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 603cd256109134..89e7fe9e7cfb29 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -4112,7 +4112,7 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, } #endif // defined(TARGET_ARM64) || defined(TARGET_RISCV64) -#if defined(TARGET_XARCH) || defined(TARGET_ARM64) || defined(TARGET_RISCV64) +#if defined(TARGET_64BIT) // TODO-ARM-CQ: reenable treating InterlockedCmpXchg32 operation as intrinsic case NI_System_Threading_Interlocked_CompareExchange: { @@ -4122,12 +4122,15 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, { break; } -#if !defined(TARGET_XARCH) && !defined(TARGET_ARM64) +#if defined(TARGET_RISCV64) + // CAS for small types is natively supported starting with the Zacas extension in Linux 6.8; however, hardware support + // for RVA23 profile is not available at the time of writing. else if (genTypeSize(retType) < 4) { + mustExpand = false; break; } -#endif // !defined(TARGET_XARCH) && !defined(TARGET_ARM64) +#endif // defined(TARGET_RISCV64) if ((retType == TYP_REF) && (impStackTop(1).val->IsIntegralConst(0) || impStackTop(1).val->IsIconHandle(GTF_ICON_OBJ_HDL))) @@ -4164,12 +4167,15 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, { break; } -#if !defined(TARGET_XARCH) && !defined(TARGET_ARM64) +#if defined(TARGET_RISCV64) + // CAS for small types is natively supported starting with the Zacas extension in Linux 6.8; however, hardware support + // for RVA23 profile is not available at the time of writing. else if (genTypeSize(retType) < 4) { + mustExpand = false; break; } -#endif // !defined(TARGET_XARCH) && !defined(TARGET_ARM64) +#endif // defined(TARGET_RISCV64) if ((retType == TYP_REF) && (impStackTop().val->IsIntegralConst(0) || impStackTop().val->IsIconHandle(GTF_ICON_OBJ_HDL))) @@ -4199,7 +4205,7 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, callType, op1, op2); break; } -#endif // defined(TARGET_XARCH) || defined(TARGET_ARM64) || defined(TARGET_RISCV64) +#endif // defined(TARGET_64BIT) case NI_System_Threading_Interlocked_MemoryBarrier: { From d2231011a98d3d3f6c58be888334960e0df00c17 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Sun, 9 Mar 2025 13:28:55 +0200 Subject: [PATCH 2/6] fmt --- src/coreclr/jit/importercalls.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 89e7fe9e7cfb29..32e46fe0e2ffa2 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -4123,8 +4123,8 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, break; } #if defined(TARGET_RISCV64) - // CAS for small types is natively supported starting with the Zacas extension in Linux 6.8; however, hardware support - // for RVA23 profile is not available at the time of writing. + // CAS for small types is natively supported starting with the Zacas extension in Linux 6.8; however, + // hardware support for RVA23 profile is not available at the time of writing. else if (genTypeSize(retType) < 4) { mustExpand = false; @@ -4168,8 +4168,8 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, break; } #if defined(TARGET_RISCV64) - // CAS for small types is natively supported starting with the Zacas extension in Linux 6.8; however, hardware support - // for RVA23 profile is not available at the time of writing. + // CAS for small types is natively supported starting with the Zacas extension in Linux 6.8; however, + // hardware support for RVA23 profile is not available at the time of writing. else if (genTypeSize(retType) < 4) { mustExpand = false; From 4638f0996b0b07bbb2ffd8778098a81f3880f741 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Sun, 9 Mar 2025 13:58:39 +0200 Subject: [PATCH 3/6] Fix linux-x86 build --- src/coreclr/jit/importercalls.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 32e46fe0e2ffa2..c856ce5f25f76c 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -4112,7 +4112,7 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, } #endif // defined(TARGET_ARM64) || defined(TARGET_RISCV64) -#if defined(TARGET_64BIT) +#if defined(TARGET_64BIT) || defined(TARGET_X86) // TODO-ARM-CQ: reenable treating InterlockedCmpXchg32 operation as intrinsic case NI_System_Threading_Interlocked_CompareExchange: { @@ -4205,7 +4205,7 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, callType, op1, op2); break; } -#endif // defined(TARGET_64BIT) +#endif // defined(TARGET_64BIT) || defined(TARGET_X86) case NI_System_Threading_Interlocked_MemoryBarrier: { From 882f9f97cf90ba17d7d811044bd3971573665684 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Sun, 9 Mar 2025 14:31:05 +0200 Subject: [PATCH 4/6] Update comments --- src/coreclr/jit/importercalls.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index c856ce5f25f76c..03ccf79c68c763 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -4123,7 +4123,7 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, break; } #if defined(TARGET_RISCV64) - // CAS for small types is natively supported starting with the Zacas extension in Linux 6.8; however, + // CAS for small types is natively supported starting with the Zabha extension in Linux 6.8; however, // hardware support for RVA23 profile is not available at the time of writing. else if (genTypeSize(retType) < 4) { @@ -4168,7 +4168,7 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, break; } #if defined(TARGET_RISCV64) - // CAS for small types is natively supported starting with the Zacas extension in Linux 6.8; however, + // CAS for small types is natively supported starting with the Zabha extension in Linux 6.8; however, // hardware support for RVA23 profile is not available at the time of writing. else if (genTypeSize(retType) < 4) { From cc4be068c46ee690701ff39ff8faee77beb6eb4e Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Sun, 9 Mar 2025 14:32:23 +0200 Subject: [PATCH 5/6] Update importercalls.cpp --- src/coreclr/jit/importercalls.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 03ccf79c68c763..71902e6c3c2c52 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -4123,7 +4123,7 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, break; } #if defined(TARGET_RISCV64) - // CAS for small types is natively supported starting with the Zabha extension in Linux 6.8; however, + // CAS for small types is natively supported starting with the Zabha extension; however, // hardware support for RVA23 profile is not available at the time of writing. else if (genTypeSize(retType) < 4) { @@ -4168,7 +4168,7 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, break; } #if defined(TARGET_RISCV64) - // CAS for small types is natively supported starting with the Zabha extension in Linux 6.8; however, + // CAS for small types is natively supported starting with the Zabha extension; however, // hardware support for RVA23 profile is not available at the time of writing. else if (genTypeSize(retType) < 4) { From c76e3c102a1d5a900e39cef9b32c818c6e29744a Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Sun, 9 Mar 2025 14:50:01 +0200 Subject: [PATCH 6/6] Handle LA64 differently --- src/coreclr/jit/importercalls.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 71902e6c3c2c52..8a8c96c7cfe44c 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -4116,6 +4116,12 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, // TODO-ARM-CQ: reenable treating InterlockedCmpXchg32 operation as intrinsic case NI_System_Threading_Interlocked_CompareExchange: { +#if defined(TARGET_LOONGARCH64) + // GT_CMPXCHG is NYI in lsraloongarch64 + mustExpand = false; + break; +#endif + var_types retType = JITtype2varType(sig->retType); if (genTypeSize(retType) > TARGET_POINTER_SIZE) @@ -4161,6 +4167,12 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, case NI_System_Threading_Interlocked_Exchange: case NI_System_Threading_Interlocked_ExchangeAdd: { +#if defined(TARGET_LOONGARCH64) + // GT_XADD and GT_XCHG are NYI in lsraloongarch64 + mustExpand = false; + break; +#endif + var_types retType = JITtype2varType(sig->retType); if (genTypeSize(retType) > TARGET_POINTER_SIZE)