-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Eliminate GenTreeRegVar and GT_REG_VAR and RegVar #18317
Conversation
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.
This reverts commit 1fc647d.
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.
This reverts commit 5bdc8a6.
This reverts commit e5505c4.
This reverts commit dbc8208.
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.
This reverts commit 6959a3c.
This reverts commit 7aa42ca.
This reverts commit dbc8208.
This reverts commit 6959a3c.
This reverts commit fc47321.
This reverts commit 5bdc8a6.
This reverts commit e5505c4.
gentree.h - fixed comment rationalize.cpp - removed code left over from removal of GT_REG_VAR case
|
LGTM overall - thanks!! It will be great to see these gone. |
CarolEidt
left a comment
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.
A couple of asserts are needed.
src/jit/compiler.cpp
Outdated
| { | ||
| chars += printf("[REG_BIRTH]"); | ||
| } | ||
| chars += printf("[REG_BIRTH]"); |
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 flag isn't really in use, but #18196 will take care of eliminating it.
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 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.
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.
Based on @mikedn 's comment I will remove it now.
src/jit/gcinfo.cpp
Outdated
| unsigned lclNum = 0; | ||
| if (tgtAddr->gtOper == GT_LCL_VAR) | ||
| { | ||
| lclNum = tgtAddr->gtLclVar.gtLclNum; |
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.
Since the case below is now gone, this should have an assert(tgtAddr->gtOper == GT_LCL_VAR);
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.
Looks like not even an assert is needed since it's obvious that tgtAddr is GT_LCL_VAR already.
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.
Oh, right!
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.
Similar to the previous case, you should replace these 5 lines with:
unsigned lclNum = tgtAddr->AsLclVar()->GetLclNum();
src/jit/codegencommon.cpp
Outdated
| wbKind = CWBKind_OtherByRefLocal; // Unclassified local variable. | ||
| unsigned lclNum = 0; | ||
| if (lcl->gtOper == GT_LCL_VAR) | ||
| lclNum = lcl->gtLclVarCommon.gtLclNum; |
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.
Since the case below is now gone, this should have an assert(tgtAddr->gtOper == GT_LCL_VAR);
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.
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.
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.
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();
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.
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 |
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.
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 |
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.
@CarolEidt Is this comment change valid? I don't think GTF_REG_BIRTH is used at all now.
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.
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; |
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.
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.
|
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. |
|
@juliusfriedman Are you still planning to work on this? |
|
Sorry for the delay, just noticed... if you need something else done outside of the commit just lmk. |
|
There's some feedback in the review comments, a couple of |
CarolEidt
left a comment
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.
@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).
src/jit/codegencommon.cpp
Outdated
| wbKind = CWBKind_OtherByRefLocal; // Unclassified local variable. | ||
| unsigned lclNum = 0; | ||
| if (lcl->gtOper == GT_LCL_VAR) | ||
| lclNum = lcl->gtLclVarCommon.gtLclNum; |
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.
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.)
src/jit/gcinfo.cpp
Outdated
| unsigned lclNum = 0; | ||
| if (tgtAddr->gtOper == GT_LCL_VAR) | ||
| { | ||
| lclNum = tgtAddr->gtLclVar.gtLclNum; |
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.
Similar to the previous case, you should replace these 5 lines with:
unsigned lclNum = tgtAddr->AsLclVar()->GetLclNum();
juliusfriedman
left a comment
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.
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.
src/jit/codegencommon.cpp
Outdated
| wbKind = CWBKind_OtherByRefLocal; // Unclassified local variable. | ||
| unsigned lclNum = 0; | ||
| if (lcl->gtOper == GT_LCL_VAR) | ||
| lclNum = lcl->gtLclVarCommon.gtLclNum; |
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.
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.
|
@CarolEidt, @BruceForstall,@mikedn, @danmosemsft |
|
test Ubuntu16.04 arm64 Cross Checked no_tiered_compilation_innerloop Build and Test |
CarolEidt
left a comment
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 - thanks for doing this - and for your patience!
No, we didn't. The changes seemed to all be benign/no-ops, but apparently they were not. |
|
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. |
Issue dotnet/coreclr#18201 / Hackathon Commit migrated from dotnet/coreclr@e1a5d0f


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