-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Optimization. Use Min/Max intrinsics if one of arguments is constant. #69434
Conversation
Tagging subscribers to this area: @JulieLeeMSFT Issue Details@tannergooding I had spent some time and implemented HW intrinstics for Min/Max and as asmdiffs shows more regressions I assume I did it wrong. I also couldn't figured it how to force the containment, I've always gotten something like this: Alternatively, I tried to investigagate the lowering way and change ContainCheckIntrinsic method, but ended up with the IsContainableMemoryOp check is never true for Math.Min/Math.Max. The only option I had was marking both op's with SetRegOptional which doesn't seem right. I would be so happy if you pushed me to the right direction :) This PR was created due #65700 had been closed.
|
Could you share what C# code you're using to get this. At first glance this looks like it might be a loop and so the relevant data may be getting hoisted. A simple: |
Yes, you are right. I was using this loop to force it to be optimized:
There are not JitDisasm output when I use these flags: COMPlus_TieredCompilation=0 COMPlus_JITMinOpts=1, so I used the loop :) |
This will disable all JIT optimizations so you should not set this. |
You are right, my code was inlined so there was not any output. Thank you, now It works 💯 @tannergooding @jakobbotsch What do you think of this implementation? |
a9fbdbe
to
7331188
Compare
# Conflicts: # src/coreclr/jit/gentree.h
src/coreclr/jit/importer.cpp
Outdated
impPopStack().val; | ||
impPopStack().val; | ||
|
||
op1 = gtNewSimdHWIntrinsicNode(TYP_SIMD16, op1, NI_Vector128_CreateScalarUnsafe, callJitType, 16); |
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.
Given the assert and that we now have GT_CNS_VEC
, this should probably be:
GenTreeVecCon* vecCon = gtNewVconNode(TYP_SIMD16, callJitType);
if (callJitType == CORINFO_TYPE_FLOAT)
{
vecCon->gtSimd16Val.f32[0] = (float)op1->AsDblCon()->gtDconVal;
}
else
{
vecCon->gtSimd16Val.f64[0] = op1->AsDblCon()->gtDconVal;
}
op1 = vecCon;
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.
Otherwise the JIT is just going to have to convert the CreateScalarUnsafe
back to a GT_CNS_VEC
later in morph.
@tannergooding Could you assist me with figuring out why I'm getting compilation failures during spmi replays. It feels like I'm missing something. |
Its not clear to me at a glance. Many methods are failing with The PR isn't changing the JIT/EE version and isn't adding anything that should really cause an issue here. Maybe try merging in latest |
We don't do a good job of surfacing the assertion failures in superpmi-replay pipeline -- it takes some digging (usually jit devs run the replays locally, where it is more visible). In this case the failure is: [18:57:25] ISSUE: <ASSERT> #45239 D:\a\_work\1\s\src\coreclr\jit\importer.cpp (4600) - Assertion failed 'ni == NI_System_Math_Min' in 'C:M(double):int' during 'Importation' (IL size 54; hash 0x97f702cc; FullOpts) which looks related to the change. |
@tannergooding @jakobbotsch I made some adjustments, but CI failed with: Assert failure(PID 5132 [0x0000140c], Thread: 4600 [0x11f8]): m_alignpad == 0
File: D:\a\_work\1\s\src\coreclr\vm\syncblk.cpp Line: 2952 runtime/src/coreclr/vm/syncblk.cpp Lines 2947 to 2958 in 6be8d27
during System.Text.Json tests. I run the tests on my local machine and couldn't reproduce the failure. I also run Fuzzlyn to find an issue, but got nothing. |
That one looks like #70231 |
3a1fa1a
to
1aed08f
Compare
Co-authored-by: Jakob Botsch Nielsen <[email protected]>
Co-authored-by: Jakob Botsch Nielsen <[email protected]>
@jakobbotsch Is there a way to restart CI pipelines? It seems like the current run is stuck. |
@SkiFoD I've restarted the failing jobs. |
@tannergooding @jakobbotsch Yay, looks like it is working. Thank you a lot for your help. I have learnt a lot 👍 |
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.
LGTM. Assuming @jakobbotsch has no more feedback I think this can be merged
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.
LGTM to me too
fixes #65625
![image](https://user-images.githubusercontent.com/18483133/168826648-56318a63-73fd-4b23-bc8c-c7fcc264ea35.png)
@tannergooding I had spent some time and implemented HW intrinstics for Min/Max and as asmdiffs shows more regressions I assume I did it wrong. I also couldn't figured it how to force the containment, I've always gotten something like this:
if I understand the role of "containment" right then vmovss must go away.
Alternatively, I tried to investigagate the lowering way and change ContainCheckIntrinsic method, but ended up with the IsContainableMemoryOp check is never true for Math.Min/Math.Max. The only option I had was marking both op's with SetRegOptional which doesn't seem right.
I would be so happy if you pushed me to the right direction :)
This PR was created due #65700 had been closed.