Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Updating the x86 HWIntrinsic importer to not inline when returning gtNewMustThrowException#15772

Merged
tannergooding merged 1 commit into
dotnet:masterfrom
tannergooding:hwintrin-expand
Jan 7, 2018
Merged

Updating the x86 HWIntrinsic importer to not inline when returning gtNewMustThrowException#15772
tannergooding merged 1 commit into
dotnet:masterfrom
tannergooding:hwintrin-expand

Conversation

@tannergooding
Copy link
Copy Markdown
Member

Fixes a case where the inliner asserts when optimizations are enabled (see #15771 (comment)).

@tannergooding
Copy link
Copy Markdown
Member Author

There are actually 3 other cases that will likely need to get fixed as well.

These are the varTypeIsLong(callType) checks on _TARGET_X86_, but they happen for IsSupported = true.

I'm currently building for x86 locally and testing the fix works before I push.

@tannergooding
Copy link
Copy Markdown
Member Author

FYI. @fiigii

@tannergooding
Copy link
Copy Markdown
Member Author

All cases should be fixed.

@tannergooding
Copy link
Copy Markdown
Member Author

FYI. @AndyAyersMS. Updated to pass down mustExpand from impIntrinsic as requested.

Copy link
Copy Markdown
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@tannergooding
Copy link
Copy Markdown
Member Author

Applied the formatting patch.

Copy link
Copy Markdown

@fiigii fiigii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching the bug!

Comment thread src/jit/compiler.h
GenTree* impSSEIntrinsic(NamedIntrinsic intrinsic,
CORINFO_METHOD_HANDLE method,
CORINFO_SIG_INFO* sig,
bool mustExpand);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you pass mustExpand into impXXXIntrinsic, it seems only required by impX86HWIntrinsic.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also used (in this PR) by Crc32, Lzcnt, and Popcnt, since they throw PNSE when varTypeIsLong(callType)

It will also need to be used by instructions like Sse.Shuffle to determine whether we should fallback to a GT_CALL or allow the instruction to be inlined (when op3 is not a constant).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all the exception code can be unified to impX86HWIntrinsic with the table-driven approach. Now, perhaps you can directly extract the scalar intrinsic's exception code to impX86HWIntrinsic. Then I will improve it in the table-driven PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably do that particular refactoring with the table driven PR. The varTypeIsLong check shouldn't be for all instructions even after refactoring, so there isn't a good place to put it in impX86HWIntrinsic beforehand.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

Comment thread src/jit/hwintrinsicxarch.cpp Outdated
{
// When we aren't supported we need to return nullptr when attempting to expand inline
// (gtIsRecursiveCall == false) as the gtNewMustThrowException node can mess with the
// inliner in unexpected ways.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment looks a bit unclear.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try and clarify.

Basically, this is saying we've hit a failure case and we need to return nullptr if mustExpand is false, since that means we were attempting to expand the intrinsic inline another method. However, when mustExpand is true, it means we are expanding the intrinsic inline a GT_CALL to ourselves, so we can return the exception.

We do this because the inliner expects the intrinsic, not an exception, and will otherwise fail.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Hopefully the new wording is easier to understand.

Comment thread src/jit/hwintrinsicxarch.cpp Outdated
impPopStack();
}

return gtNewMustThrowException(CORINFO_HELP_THROW_PLATFORM_NOT_SUPPORTED, JITtype2varType(sig->retType),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, parametrizing the exception would be better. We will need other exceptions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other exceptions are we going to need (I'll parameterize it, just interested as I wasn't aware of others)?

Copy link
Copy Markdown

@fiigii fiigii Jan 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we will need other exceptions for out of range arguments and non-numeric type arguments, but depends on our future implementation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

I had thought we were just going to throw PNSE for those as well, but have a more explicit failure makes sense as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Copy Markdown

@fiigii fiigii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@tannergooding
Copy link
Copy Markdown
Member Author

Logged https://github.com/dotnet/coreclr/issues/15778 for the CROSS check issue.

@tannergooding
Copy link
Copy Markdown
Member Author

@jkotas, am I good to merge this, despite the CROSS check issue, or should I wait for that to be resolved first?

@jkotas
Copy link
Copy Markdown
Member

jkotas commented Jan 7, 2018

am I good to merge this

I think so.

@tannergooding tannergooding merged commit d36b8e1 into dotnet:master Jan 7, 2018
@MattGal
Copy link
Copy Markdown
Member

MattGal commented Jan 8, 2018

@dotnet-bot test cross please

@MattGal
Copy link
Copy Markdown
Member

MattGal commented Jan 8, 2018

@dotnet-bot help

@tannergooding tannergooding deleted the hwintrin-expand branch January 17, 2018 01:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants