From d0c6893d3d7ff50514a8b8cdb75b6f287890d19e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= <35800402+MichalPetryka@users.noreply.github.com> Date: Sat, 10 Feb 2024 19:53:54 +0100 Subject: [PATCH 1/2] Fix failing BitCast test --- src/coreclr/jit/importercalls.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 51251adad72ae5..91a3cceb9bb17c 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -4317,6 +4317,9 @@ GenTree* Compiler::impSRCSUnsafeIntrinsic(NamedIntrinsic intrinsic, valType = lvaGetDesc(effectiveVal->AsLclVar()->GetLclNum())->TypeGet(); } + bool requiresUnaligned = info.compCompHnd->getClassAlignmentRequirement(fromTypeHnd) < + info.compCompHnd->getClassAlignmentRequirement(toTypeHnd); + // Handle matching handles, compatible struct layouts or integrals where we can simply return op1 if (varTypeIsSmall(toType)) { @@ -4330,7 +4333,7 @@ GenTree* Compiler::impSRCSUnsafeIntrinsic(NamedIntrinsic intrinsic, } } else if (((toType != TYP_STRUCT) && (genActualType(valType) == toType)) || - ClassLayout::AreCompatible(fromLayout, toLayout)) + (!requiresUnaligned && ClassLayout::AreCompatible(fromLayout, toLayout))) { return op1; } @@ -4396,8 +4399,7 @@ GenTree* Compiler::impSRCSUnsafeIntrinsic(NamedIntrinsic intrinsic, addr = impGetNodeAddr(op1, CHECK_SPILL_ALL, &indirFlags); } - if (info.compCompHnd->getClassAlignmentRequirement(fromTypeHnd) < - info.compCompHnd->getClassAlignmentRequirement(toTypeHnd)) + if (requiresUnaligned) { indirFlags |= GTF_IND_UNALIGNED; } From dfe0466c34f52111f5cd49906462fb4cf7fc5fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= <35800402+MichalPetryka@users.noreply.github.com> Date: Sat, 10 Feb 2024 20:12:51 +0100 Subject: [PATCH 2/2] Update importercalls.cpp --- src/coreclr/jit/importercalls.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index 91a3cceb9bb17c..98e05a4f62606b 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -4318,7 +4318,7 @@ GenTree* Compiler::impSRCSUnsafeIntrinsic(NamedIntrinsic intrinsic, } bool requiresUnaligned = info.compCompHnd->getClassAlignmentRequirement(fromTypeHnd) < - info.compCompHnd->getClassAlignmentRequirement(toTypeHnd); + info.compCompHnd->getClassAlignmentRequirement(toTypeHnd); // Handle matching handles, compatible struct layouts or integrals where we can simply return op1 if (varTypeIsSmall(toType))