diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index f24c4cae31ef2..2d5a1eaba9df4 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -30912,9 +30912,10 @@ GenTree* Compiler::gtFoldExprHWIntrinsic(GenTreeHWIntrinsic* tree) int64_t shiftAmount = otherNode->AsVecCon()->GetElementIntegral(TYP_LONG, 0); - if ((genTypeSize(simdBaseType) != 8) && (shiftAmount > INT_MAX)) + if (static_cast(shiftAmount) >= + (static_cast(genTypeSize(simdBaseType)) * BITS_PER_BYTE)) { - // Ensure we don't lose track the the amount is an overshift + // Set to -1 to indicate an explicit overshift shiftAmount = -1; } diff --git a/src/coreclr/jit/simd.h b/src/coreclr/jit/simd.h index f1294cb1a9547..04b245ecb7495 100644 --- a/src/coreclr/jit/simd.h +++ b/src/coreclr/jit/simd.h @@ -797,12 +797,16 @@ TBase EvaluateBinaryScalarSpecialized(genTreeOps oper, TBase arg0, TBase arg1) case GT_ROL: { + // Normalize the "rotate by" value + arg1 %= (sizeof(TBase) * BITS_PER_BYTE); return EvaluateBinaryScalarSpecialized(GT_LSH, arg0, arg1) | EvaluateBinaryScalarRSZ(arg0, (sizeof(TBase) * 8) - arg1); } case GT_ROR: { + // Normalize the "rotate by" value + arg1 %= (sizeof(TBase) * BITS_PER_BYTE); return EvaluateBinaryScalarRSZ(arg0, arg1) | EvaluateBinaryScalarSpecialized(GT_LSH, arg0, (sizeof(TBase) * 8) - arg1); } diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 2e88aef9bb93d..f48dc75d831ab 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -8244,14 +8244,14 @@ ValueNum ValueNumStore::EvalHWIntrinsicFunBinary(GenTreeHWIntrinsic* tree, // 64-bits. uint64_t shiftAmount = GetConstantSimd16(arg1VN).u64[0]; + if (shiftAmount >= (static_cast(genTypeSize(baseType)) * BITS_PER_BYTE)) + { + // Set to -1 to indicate an explicit overshift + shiftAmount = -1; + } if (genTypeSize(baseType) != 8) { - if (shiftAmount > INT_MAX) - { - // Ensure we don't lose track the the amount is an overshift - shiftAmount = -1; - } arg1VN = VNForIntCon(static_cast(shiftAmount)); } else diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_105558/Runtime_105558.cs b/src/tests/JIT/Regression/JitBlue/Runtime_105558/Runtime_105558.cs new file mode 100644 index 0000000000000..7c5bc96afea96 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_105558/Runtime_105558.cs @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// Generated by Fuzzlyn v2.1 on 2024-07-26 12:56:41 +// Run on X64 Windows +// Seed: 13544108888657591911-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base +// Reduced from 290.9 KiB to 0.6 KiB in 00:02:37 +// Debug: Prints 1 line(s) +// Release: Prints 0 line(s) + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; +using Xunit; + +public struct S0 +{ + public int F0; +} + +public struct S1 +{ + public S0 F5; +} + +public class Runtime_105558 +{ + public static S1 s_3; + + [Fact] + public static void TestEntryPoint() + { + if (Sse2.IsSupported) + { + ShiftRightLogicalTest(); + } + if (Avx512F.IsSupported) + { + Avx512FRotateRightTest(); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void ShiftRightLogicalTest() + { + var vr17 = Vector128.CreateScalar(2558356441U); + var vr18 = Vector128.Create(0, 3113514718U, 0, 0); + var vr19 = Sse2.ShiftRightLogical(vr17, vr18); + if (Sse2.ConvertToUInt32(vr19) != 0) + throw new InvalidOperationException(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void Avx512FRotateRightTest() + { + var vr1 = Vector128.CreateScalar(1); + Vector128 vr2 = Avx512F.VL.RotateRight(vr1, 84); + if (vr2.GetElement(0) != 4096) + throw new InvalidOperationException(); + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_105558/Runtime_105558.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_105558/Runtime_105558.csproj new file mode 100644 index 0000000000000..de6d5e08882e8 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_105558/Runtime_105558.csproj @@ -0,0 +1,8 @@ + + + True + + + + +