-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Conversation
Support for new-style intrinsics where corelib methods can have both IL implementations and optional jit-supplied implementations. Mark such methods with the [Intrinsic] attribute, then recognize the intrinsic methods by name in the jit. Jit currently has a placeholder for the Enum.HasFlag method. Not sure what to call these (currently "Jit Intrinsic") and whether the attribute lookup is being done in the right spot.
Also put the jit change under debug, since it only handles detecting the new intrinsic call, not transforming it. Add the explanatory note to Enum.cs about R4/R8 support.
cc @dotnet/jit-contrib There is always some interface related bit I forget to fix, because we never build it by default anywhere -- anyone remember what that is? [Never mind, found it...] Will need some up-front desktop changes; also bumps the jit GUID so will need new SPMI data. |
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false)] |
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.
This might (?) be a good place for a comment indicating that the jit MAY replace direct calls to [Intrinsic]
methods with its own sequence, but that it also may opt to fall back on the MSIL implementation (and presumably indirect calls will execute the fall-back implementation?).
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.
Added.
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.
Thanks!
Need to lay some groundwork on the desktop side before this can go in. |
Something about this change seems to be causing the ubuntu and tizen arm test legs to time out. There's nothing platform or arch specific here so it is a bit of a puzzle why they are selectively impacted. Also seeing the regexdna failure on OSX. |
Maybe I need to explicitly clear the intrinsic flag in |
It should not be needed. All MethodDesc flags are zero-initialized. |
Hmm, going to try and repro this locally, as those legs don't give much insight as to what they are doing during the test execution phase. |
As best I can tell it is stuck running the first test:
|
I can't get a user mode debugger attached yet, but I enabled system call tracing in qemu and it looks like the process is stuck in some kind of waiting pattern:
@dotnet/arm32-contrib @janvorli any ideas what might be going wrong here? Any tips on how to debug corerun running under qemu inside docker on ubuntu? |
@AndyAyersMS as for debugging inside qemu, I think that you should be run gdb or at least gdbserver inside qemu. But maybe the easiest way is to borrow a Raspberry PI 2 or 3 and debug the stuff on it. You may also be able to use the new createdump tool that's built in the coreclr repo. According to @mikem8361, it should be able to create a dump of a live process. |
Using a checked runtime gives the following clue:
So maybe something in the jit intrinsic handling gets messed up. Still digging... |
The assert fires after the first jitted method is run (no crossgen, so this is System.AppDomain::SetupDomain). With this change the jit does not attempt to process any intrinsics in that method (haven't checked what happens without the change yet). Removing the second if (pMD->IsFCallOrIntrinsic())
result |= CORINFO_FLG_NOGCCHECK | CORINFO_FLG_INTRINSIC;
if (pMD->IsJitIntrinsic())
result |= CORINFO_FLG_JIT_INTRINSIC | CORINFO_FLG_INTRINSIC; So I wonder if maybe this is a compiler bug, and because of it, we end up not setting the intrinsic flag when we should? Am going to add an assert at the end to see.... |
Above seems more plausible now -- adding if (pMD->IsFCallOrIntrinsic())
{
_ASSERTE((result & CORINFO_FLG_INTRINSIC) != 0);
} to the end of |
Revised the code so that we no longer set CORINFO_FLG_INTRINSIC for the new intrinsics. Instead we look for both intrinsic flags on the jit side. |
Hmm, looks like some legs are hitting an infrastructure issue:
|
@dotnet/dnceng some connectivity issues with the perf correctness legs since about 9AM. |
AGH.....I had uninstalled git and reinstalled it....why is it having cert issues. |
Looks like maybe the perf correctness issues are fixed ;-- wii retry. |
The new jit interface method is stubbed out in desktop, as we will not see any of these new style intriniscs there (at least for now). [tfs-changeset: 1673063]
Check for calls to `Enum.HasFlag` using the new named intrinsic support introduced in dotnet#13815. Implement a simple recognizer for these named intrinsics (currently just recognizing `Enum.HasFlag`). When the call is recognized, optimize if both operands are boxes with compatible types and both boxes can be removed. The optimization changes the call to a simple and/compare tree on the underlying enum values. To accomplish this, generalize the behavior of `gtTryRemoveBoxUpstreamEffects` to add a "trial removal" mode and to optionally suppress narrowing of the copy source. Invoke the optimization during importation (which will catch most cases) and again during morph (to get the post-inline cases). Added test cases. Suprisingly there were almost no uses of HasFlag in the current CoreCLR test suite. Closes #5626.
Check for calls to `Enum.HasFlag` using the new named intrinsic support introduced in #13815. Implement a simple recognizer for these named intrinsics (currently just recognizing `Enum.HasFlag`). When the call is recognized, optimize if both operands are boxes with compatible types and both boxes can be removed. The optimization changes the call to a simple and/compare tree on the underlying enum values. To accomplish this, generalize the behavior of `gtTryRemoveBoxUpstreamEffects` to add a "trial removal" mode and to optionally suppress narrowing of the copy source. Invoke the optimization during importation (which will catch most cases) and again during morph (to get the post-inline cases). Added test cases. Suprisingly there were almost no uses of HasFlag in the current CoreCLR test suite. Closes #5626.
@AndyAyersMS @jkotas Could you please explain this more? I am using the new JIT intrinsic recognizer to implement Intel hardware intrinsics. |
The hardware intrinsics has to be always expanded unconditionally, even when optimizations are off. |
So the new jit intrinsic expansion depends on optimization config? |
Right. It is how the intrinsic expansion has been historically always wired in the JIT - it was turned on only when optimizations are on. |
@jkotas Thanks. I think we should resolve this now. I have implemented |
I would defer to @dotnet/jit-contrib on details how the hardware intrinsics expansion should be wired in the JIT. Maybe you can open WIP PR with what you have done for IsSupported and the details can be discussed there. |
Will do. |
Implementation for new-style jit intrinsics, for methods with IL implementations that have known behaviors. The jit can replace these with alternate implementations if it so chooses.
I have been using
Enum.HasFlag
as a test case, and so have marked it here as[Intrinsic]
. The jit currently recognizes the call as a new-style intrinsic but does not yet optimize.Related issue: #13813.
Plan on doing some cleanup once there is agreement on naming and other aspects of the implementation.
Desktop implementation of the jit interface (not shown) will be stubbed out to always return null values for the new jit interface call.