Skip to content

Branchless codegen for lifted nullable operators#25992

Merged
gafter merged 1 commit intodotnet:masterfrom
alrz:lifted-op
Apr 6, 2018
Merged

Branchless codegen for lifted nullable operators#25992
gafter merged 1 commit intodotnet:masterfrom
alrz:lifted-op

Conversation

@alrz
Copy link
Copy Markdown
Member

@alrz alrz commented Apr 6, 2018

Fixes #17261

@alrz alrz requested a review from a team as a code owner April 6, 2018 14:10
// tempx.HasValue == tempy.HasValue :
// false;
// result = (tempx.GetValueOrDefault() == tempy.GetValueOrDefault()) &
// (tempx.HasValue == tempy.HasValue);
Copy link
Copy Markdown
Contributor

@sharwell sharwell Apr 6, 2018

Choose a reason for hiding this comment

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

❔ Do we do anything special for cases where tempx or tempy is know to be a non-nullable value?

❔ Regardless of the first one, do we have tests showing the behavior where (tempx XOR tempy) is a non-nullable value?

Copy link
Copy Markdown
Member Author

@alrz alrz Apr 6, 2018

Choose a reason for hiding this comment

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

where tempx or tempy is know to be a non-nullable value?

That still use short circuiting operators,
MakeOptimizedGetValueOrDefault handles the case where either side is not nullable.

where (tempx ^ tempy) is a non-nullable value?

Only comparison operators end up here and the result is bool.

Copy link
Copy Markdown
Contributor

@sharwell sharwell Apr 6, 2018

Choose a reason for hiding this comment

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

Only comparison operators end up here and the result is bool.

Sorry for the confusion. I meant XOR, not the C# operator. As in cases where tempx is nullable or tempy is nullable, but not both.

Copy link
Copy Markdown
Member Author

@alrz alrz Apr 6, 2018

Choose a reason for hiding this comment

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

Looks like there is not (or I couldn't find it). Will add a test to verify new codegen (in followup prs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do not think this change has any effect on ^, since it is not a comparison operator.
It is worth investigating whether the same optimization is applicable to ^, but I assume that will come as another change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, I see. you meant the operands differing in being non-nullable.
Yes, it is worth adding a test.

@gafter
Copy link
Copy Markdown
Member

gafter commented Apr 6, 2018

test windows_release_unit64_prtest please

@gafter gafter requested a review from VSadov April 6, 2018 19:47
@gafter
Copy link
Copy Markdown
Member

gafter commented Apr 6, 2018

Looks good. Do you have any measurements of the runtime performance change caused by this?

Copy link
Copy Markdown
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

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

:shipit:

@gafter gafter self-assigned this Apr 6, 2018
@gafter
Copy link
Copy Markdown
Member

gafter commented Apr 6, 2018

@VSadov Could you please look at this?

@gafter gafter added this to the 15.8 milestone Apr 6, 2018
@AlekseyTs
Copy link
Copy Markdown
Contributor

If we are going ahead with this, I expect to see similar changes done in VB, unless it already generates code like that.

@alrz
Copy link
Copy Markdown
Member Author

alrz commented Apr 6, 2018

x | y and x & y on nullables also generate braching code (and has a comment for this to be considered). once confirmed, I'll change those as well. Not sure if there are any other cases.

Copy link
Copy Markdown
Member

@VSadov VSadov left a comment

Choose a reason for hiding this comment

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

LGTM

@VSadov
Copy link
Copy Markdown
Member

VSadov commented Apr 6, 2018

The other operators like |, &, ^ are worth pursuing, but better be separated in another change. Just to have one thing at a time.

It may also be worth to follow up with doing this for VB (be careful there - VB does nullable equality differently).

@VSadov
Copy link
Copy Markdown
Member

VSadov commented Apr 6, 2018

@dotnet-bot test windows_release_unit64_prtest please

@gafter
Copy link
Copy Markdown
Member

gafter commented Apr 6, 2018

Thank you so much @alrz for your contribution!

@alrz alrz deleted the lifted-op branch August 24, 2018 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants