-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mono] Generate valid LLVM IR for vectors with unsupported element types #53132
Conversation
The runtime-staging failures look relevant. |
src/mono/mono/metadata/class-init.c
Outdated
@@ -860,7 +862,7 @@ mono_class_create_generic_inst (MonoGenericClass *gclass) | |||
if (mono_is_corlib_image (gklass->image) && | |||
(!strcmp (gklass->name, "Vector`1") || !strcmp (gklass->name, "Vector64`1") || !strcmp (gklass->name, "Vector128`1") || !strcmp (gklass->name, "Vector256`1"))) { | |||
MonoType *etype = gclass->context.class_inst->type_argv [0]; | |||
if (mono_type_is_primitive (etype) && etype->type != MONO_TYPE_CHAR && etype->type != MONO_TYPE_BOOLEAN) | |||
if (!mini_is_gsharedvt_type (etype)) | |||
klass->simd_type = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
metadata/ code should not include mini.h, this should be done some other way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think this wouldn't completely fix Full AOT on arm64 because System.Runtime.Intrinsics.WithLower
will be instantiated with T_GSHAREDVT
, leading to exactly the same problem this was intended to fix; will check now and think about this a little more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it can check klass->simd_type && mini_is_gsharedvt_type (..) in the jit, and fail gsharedvt, using GSHAREDVT_FAILURE ().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried another approach.
56a21e7
to
ff5e097
Compare
Some functions never associate the mini IR source registers used with their `setret` instructions with LLVM values because they unconditionally throw. `System.Runtime.Intrinsics.X86.Aes:Decrypt` is an example of such a function; when compiled for arm64, it never returns a value and unconditionally throws a `PlatformNotSupportedException`. We already had support for handling this for some, but not all, return value passing conventions. Deduplicate this support and apply it uniformly to all return value passing conventions that expect a populated mini IR source register. Make `LLVMArgNone` specifically mean "no return value"/"`void` return type". Split from #53132. Partially fixes FullAOT compilation of System.Private.CoreLib.dll on arm64.
Why is the LLVM IR generated not simply the IL when the type isn't supported? All of I'd expect that the same happen here and so the LLVM IR should never get any vector IR for something like |
... Oh man. Thanks for the sanity check. |
Before this change, vectors with unsupported element types generated generic
"value type" code, which can cause invalid IR to be generated when compiling
System.Runtime.Intrinsics.WithLower<bool>
on arm64. For posterity, here's therelevant part of
WithLower
:Vector128.As
is currently implemented as an intrinsic that emits a bitcast,but the
Vector128<bool>
andVector64<bool>
parameters are never explicitlyloaded from a pair of GPRs into vectors in the function prologue.
Before this change,
WithLower<bool>
generates:The two bitcasts from arrays to first-class types are invalid. This would cause
an assertion failure if Mono is linked against a copy of LLVM built with
assertions enabled. With assertions disabled, this eventually causes opt/llc to
crash. This change works around this by generating
undef
values on functionentry for parameters that have SIMD-with-invalid-element types and associating
these dummy values to the mini IR registers that would be consumed by any
subsequent SIMD operations.
Future work:
FullAOT tests should be resurrected in dotnet/runtime.
The interaction between gsharedvt and SIMD types should be clarified.