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

Conversation

@juliusfriedman
Copy link

Complete. Please let me know if there is anything else.

Julius Richard Friedman added 30 commits June 1, 2018 18:48
ASCIIEncoding.cs - Updated syntax to use nameof and default and lambda, updated null checks to use "yoda" conditions, checked against false rather than performing NOT, performed parameter checks in parallel where possible, removed use of charCount in GetCharCount and used count directly. Used int.MaxValue vs 0x7fffffff in GetMaxCharCount and GetMaxByteCount, skipped declaring fallbackResult and used the value directly.

DecoderFallback.cs - Indicated Span API usefulness, marked ThrowLastBytesRecursive static. (Encoding.cs could also mark similar methods static)

EncoderFallback.cs - Updated syntax to use lamba and default, InternalGetNextChar now uses switch, InternalFallback checks against false directly instead of using NOT, marked ThrowLastCharRecursive static.

EncoderReplacementFallback.cs - Updated syntax to use lambda, default, is and yoda conditions.

EncoderReplacementFallbackBuffer.Fallback uses shift vs Divide.
ASCIIEncoding.cs - Updated syntax to use nameof and default and lambda, updated null checks to use "yoda" conditions, checked against false rather than performing NOT, performed parameter checks in parallel where possible, removed use of charCount in GetCharCount and used count directly. Used int.MaxValue vs 0x7fffffff in GetMaxCharCount and GetMaxByteCount, skipped declaring fallbackResult and used the value directly.

DecoderFallback.cs - Indicated Span API usefulness, marked ThrowLastBytesRecursive static. (Encoding.cs could also mark similar methods static)

EncoderFallback.cs - Updated syntax to use lamba and default, InternalGetNextChar now uses switch, InternalFallback checks against false directly instead of using NOT, marked ThrowLastCharRecursive static.

EncoderReplacementFallback.cs - Updated syntax to use lambda, default, is and yoda conditions.

EncoderReplacementFallbackBuffer.Fallback uses shift vs Divide.
…g "chars", noted with comment, removed commented code.

Encoding.cs - noted hardcoded string "chars".

ASCIIEncoding.cs - Added referenced to System.Numerics,System.Runtime.CompilerServices, Internal.Runtime.CompilerServices. Used references to implement TryGetAsciiChars, TryEncodeAsciiCharsToBytes and optimize GetByteCount, GetBytes, GetCharCount, GetChars using those implementations, noted Allocations used in Fallback.
Removed GPL code link for comparison.
Added 2 other resources.

Fixed order of checks (yoda conditionals)

moved calculation of charCount.

noted byteCount was already checked to be > 0.

Passed pointers by reference.

moved declaration of charEnd.

moved calculation of charCount.
codegencommon.cpp - Removed branches and asserts for GT_REG_VAR.

congenlinear.cpp - removed restoreRegVar and checks for GT_REG_VAR.

compiler.cpp - removed cases and checks for GT_REG_VAR.

compiler.h - removed GT_REG_VAR case.

compiler.hpp - removed GT_REG_VAR case.

flowgraph.cpp - removed check for GT_REG_VAR.

gcinfo.cpp - removed GT_REG_VAR case.

gentree.cpp - removed assert for size of GT_REG_VAR, removed cases for GT_REG_VAR.

gentree.h - updated comments from removing GT_REG_VAR, removed checks for GT_REG_VAR, removed asserts for GT_REG_VAR, eliminated GenTreeRegVar.

gtlist.h - removed GTNODE for REG_VAR.

gtstructs.h - removed use of GT_REG_VAR and RegVar

liveness.cpp - removed check for GT_REG_VAR.

lower.cpp - removed check in assert for GT_REG_VAR.

regset.cpp - removed assert for GT_REG_VAR.

valuenum.cpp - removed case for GT_REG_VAR.

morph.cpp - removed check for GT_REG_VAR.

rationalize.cpp - removed cases for GT_REG_VAR.
Fixed formatting errors.
codegencommon.cpp - Removed branches and asserts for GT_REG_VAR.

congenlinear.cpp - removed restoreRegVar and checks for GT_REG_VAR.

compiler.cpp - removed cases and checks for GT_REG_VAR.

compiler.h - removed GT_REG_VAR case.

compiler.hpp - removed GT_REG_VAR case.

flowgraph.cpp - removed check for GT_REG_VAR.

gcinfo.cpp - removed GT_REG_VAR case.

gentree.cpp - removed assert for size of GT_REG_VAR, removed cases for GT_REG_VAR.

gentree.h - updated comments from removing GT_REG_VAR, removed checks for GT_REG_VAR, removed asserts for GT_REG_VAR, eliminated GenTreeRegVar.

gtlist.h - removed GTNODE for REG_VAR.

gtstructs.h - removed use of GT_REG_VAR and RegVar

liveness.cpp - removed check for GT_REG_VAR.

lower.cpp - removed check in assert for GT_REG_VAR.

regset.cpp - removed assert for GT_REG_VAR.

valuenum.cpp - removed case for GT_REG_VAR.

morph.cpp - removed check for GT_REG_VAR.

rationalize.cpp - removed cases for GT_REG_VAR.
Fixed formatting errors.
codegencommon.cpp - Removed branches and asserts for GT_REG_VAR.

congenlinear.cpp - removed restoreRegVar and checks for GT_REG_VAR.

compiler.cpp - removed cases and checks for GT_REG_VAR.

compiler.h - removed GT_REG_VAR case.

compiler.hpp - removed GT_REG_VAR case.

flowgraph.cpp - removed check for GT_REG_VAR.

gcinfo.cpp - removed GT_REG_VAR case.

gentree.cpp - removed assert for size of GT_REG_VAR, removed cases for GT_REG_VAR.

gentree.h - updated comments from removing GT_REG_VAR, removed checks for GT_REG_VAR, removed asserts for GT_REG_VAR, eliminated GenTreeRegVar.

gtlist.h - removed GTNODE for REG_VAR.

gtstructs.h - removed use of GT_REG_VAR and RegVar

liveness.cpp - removed check for GT_REG_VAR.

lower.cpp - removed check in assert for GT_REG_VAR.

regset.cpp - removed assert for GT_REG_VAR.

valuenum.cpp - removed case for GT_REG_VAR.

morph.cpp - removed check for GT_REG_VAR.

rationalize.cpp - removed cases for GT_REG_VAR.
Fixed formatting errors.
Julius Richard Friedman added 6 commits June 5, 2018 17:57
gentree.h - fixed comment

rationalize.cpp - removed code left over from removal of GT_REG_VAR case
@CarolEidt
Copy link

LGTM overall - thanks!! It will be great to see these gone.
There are a couple of places that now need asserts, but otherwise this is ready to go.
If you were inclined, you could squash the commits (or we can do it on merge).

Copy link

@CarolEidt CarolEidt left a comment

Choose a reason for hiding this comment

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

A couple of asserts are needed.

{
chars += printf("[REG_BIRTH]");
}
chars += printf("[REG_BIRTH]");

Choose a reason for hiding this comment

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

This flag isn't really in use, but #18196 will take care of eliminating it.

Copy link

Choose a reason for hiding this comment

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

This entire if needs to go away. The flag only applies to GT_REG_VAR nodes so attempting to print it for other nodes will result in misleading dumps.

Copy link
Author

@juliusfriedman juliusfriedman Jun 7, 2018

Choose a reason for hiding this comment

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

Based on @mikedn 's comment I will remove it now.

unsigned lclNum = 0;
if (tgtAddr->gtOper == GT_LCL_VAR)
{
lclNum = tgtAddr->gtLclVar.gtLclNum;

Choose a reason for hiding this comment

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

Since the case below is now gone, this should have an assert(tgtAddr->gtOper == GT_LCL_VAR);

Copy link

Choose a reason for hiding this comment

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

Looks like not even an assert is needed since it's obvious that tgtAddr is GT_LCL_VAR already.

Choose a reason for hiding this comment

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

Oh, right!

Choose a reason for hiding this comment

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

Similar to the previous case, you should replace these 5 lines with:

unsigned lclNum = tgtAddr->AsLclVar()->GetLclNum();

wbKind = CWBKind_OtherByRefLocal; // Unclassified local variable.
unsigned lclNum = 0;
if (lcl->gtOper == GT_LCL_VAR)
lclNum = lcl->gtLclVarCommon.gtLclNum;

Choose a reason for hiding this comment

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

Since the case below is now gone, this should have an assert(tgtAddr->gtOper == GT_LCL_VAR);

Copy link
Author

Choose a reason for hiding this comment

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

Please clarify, the code below was an else to what is already such a check albeit a different variable. I think you mean to insert one at 3254? Just want to be correct.

Copy link

Choose a reason for hiding this comment

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

Instead of an explicit assert, gtLclVarCommon should be replaced with AsLclVar that provides the assert for free. The whole thing should be unsigned lclNum = lcl->AsLclVar()->GetLclNum();

Choose a reason for hiding this comment

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

As @mikedn has suggested, these 3 lines should just be replaced with:

unsigned lclNum = lcl->AsLclVar()->GetLclNum();

The AsLclVar() will do the assert that this is a GT_LCL_VAR node, and this should be the only kind of node we see here now.

(In general, we're moving torward the AsXX() methods instead of the gtXX tags.)

ClearRegOptional();
}

bool IsRegVarDeath() const

Choose a reason for hiding this comment

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

These two methods are not in use, bug again, #18196 can eliminate them.

// GTF_VAR_DEF && !GTF_VAR_USEASG
#define GTF_REG_BIRTH 0x04000000 // GT_REG_VAR -- enregistered variable born here
#define GTF_VAR_DEATH 0x02000000 // GT_LCL_VAR, GT_REG_VAR -- variable dies here (last use)
#define GTF_REG_BIRTH 0x04000000 // GT_LCL_VAR, -- enregistered variable born here
Copy link

Choose a reason for hiding this comment

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

@CarolEidt Is this comment change valid? I don't think GTF_REG_BIRTH is used at all now.

Choose a reason for hiding this comment

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

Right - I don't think it's correct, but I think it's reasonable to eliminate it with #18196

bool IsRegVarDeath() const
{
assert(OperGet() == GT_REG_VAR);
return (gtFlags & GTF_VAR_DEATH) ? true : false;
Copy link

Choose a reason for hiding this comment

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

The correct change in such a case would be to either delete the entire function or replace the assert with unreached(). But since these functions will probably end up being delete as @CarolEidt says, you can leave this as is.

@juliusfriedman
Copy link
Author

juliusfriedman commented Jun 7, 2018

If 18196 has decided to eliminate them I can do that also, I would like to get this sorted out and make a separate PR for that unless you guys want me to combine them.

Let me know how you want me to proceed so it's easier for you guys or what needs to be done further at this point.

@BruceForstall
Copy link

@juliusfriedman Are you still planning to work on this?

@juliusfriedman
Copy link
Author

Sorry for the delay, just noticed... if you need something else done outside of the commit just lmk.

@mikedn
Copy link

mikedn commented Dec 2, 2018

There's some feedback in the review comments, a couple of ifs that are now redundant and should be removed. Also, it would be nice to cleanup the commit history, there are a bunch of unrelated commits.

Copy link

@CarolEidt CarolEidt left a comment

Choose a reason for hiding this comment

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

@juliusfriedman - sorry for the delay. There are a couple of changes remaining, and it would be great if you could squash the commits (though I believe we can do that at merge time).

wbKind = CWBKind_OtherByRefLocal; // Unclassified local variable.
unsigned lclNum = 0;
if (lcl->gtOper == GT_LCL_VAR)
lclNum = lcl->gtLclVarCommon.gtLclNum;

Choose a reason for hiding this comment

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

As @mikedn has suggested, these 3 lines should just be replaced with:

unsigned lclNum = lcl->AsLclVar()->GetLclNum();

The AsLclVar() will do the assert that this is a GT_LCL_VAR node, and this should be the only kind of node we see here now.

(In general, we're moving torward the AsXX() methods instead of the gtXX tags.)

unsigned lclNum = 0;
if (tgtAddr->gtOper == GT_LCL_VAR)
{
lclNum = tgtAddr->gtLclVar.gtLclNum;

Choose a reason for hiding this comment

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

Similar to the previous case, you should replace these 5 lines with:

unsigned lclNum = tgtAddr->AsLclVar()->GetLclNum();

Copy link
Author

@juliusfriedman juliusfriedman left a comment

Choose a reason for hiding this comment

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

I have applied the suggested fixed in codegencommon.cpp, gcinfo.cpp and gentree.h. When removing GTF_VAR_BIRTH and GTF_VAR_DEATH I see uses of them in the genRegCopy function of codegenarmarch.cpp. It seems the branch can now be removed however that would be resolved in another commit for which addresses 18196. At the current time I will shelve the changes removing gentree.h or undo them and just apply the unreached call within IsRegVarDeath and IsRegVarBirth (gentree.h) and if desires I can make another commit to remove the branching which relies on the GTF_VAR_BIRTH and GTF_VAR_DEATH defines from the other files in another commit; or you guys are welcome to do so at merge time. Please let me know if that is acceptable and if I missed anything.

wbKind = CWBKind_OtherByRefLocal; // Unclassified local variable.
unsigned lclNum = 0;
if (lcl->gtOper == GT_LCL_VAR)
lclNum = lcl->gtLclVarCommon.gtLclNum;
Copy link
Author

Choose a reason for hiding this comment

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

Please clarify, the code below was an else to what is already such a check albeit a different variable. I think you mean to insert one at 3254? Just want to be correct.

…um()` instead of inline ceremony.

gcinfo.cpp - gcWriteBarrierFromTargetAddress; used `lcl->AsLclVar()->GetLclNum()` instead of inline ceremony.

gentree.h IsRegVarDeath and IsRegVarBirth now call unreached to prepare for removal.
@juliusfriedman
Copy link
Author

juliusfriedman@09e9b4b

@juliusfriedman
Copy link
Author

@CarolEidt, @BruceForstall,@mikedn, @danmosemsft
Please let me know if anything else is required;

@CarolEidt
Copy link

test Ubuntu16.04 arm64 Cross Checked no_tiered_compilation_innerloop Build and Test

Copy link

@CarolEidt CarolEidt left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for doing this - and for your patience!

@CarolEidt CarolEidt merged commit e1a5d0f into dotnet:master Dec 11, 2018
morganbr pushed a commit that referenced this pull request Dec 14, 2018
@AndyAyersMS
Copy link
Member

Did we look at diffs for this? Benchview reports a regression on x64 ubuntu:

image

@CarolEidt
Copy link

Did we look at diffs for this?

No, we didn't. The changes seemed to all be benign/no-ops, but apparently they were not.

@mikedn
Copy link

mikedn commented Dec 15, 2018

Are we sure that the regression was caused by this change? I tried to revert the change and I can't find any diffs, at least when using the Linux AltJit. Diffed framework, diffed benchmark, tried PMI, nothing.

@AndyAyersMS
Copy link
Member

No, not sure. Thanks for digging in.

I took a wider look (past 1000 results) and this benchmark has a slower level that can remain stable for long periods of time.

So it appears this is "normal" behavior and there's no regression.

(colors swapped from above, blue is now Ubuntu, green, Windows)

image

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants