-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
JIT: Produce correctly typed IR in TLS helper expansion #108836
Conversation
The TLS helper expansion would produce `ADD(long, int)` trees like ``` ▌ STORE_LCL_VAR long V01 rat0 └──▌ ADD long ├──▌ ADD long │ ├──▌ LCL_VAR long V02 rat1 │ └──▌ CNS_INT int 72 $41 └──▌ CNS_INT long 192 ``` which is not legal IR. Fix that by inserting a cast. Also do some more aggressive folding to get rid of these casts in the normal cases, and to fold some constant arithmeticf in other cases.
cc @dotnet/jit-contrib PTAL @kunalspathak |
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.
Added a question.
I did verify the difference between my local disasm vs. what jit-diff is showing. The reason I didn't see diff locally was because on a standalone app, the tlsindex value was low that was getting removed because we were able to use an addressing mode to load it. However, in jit-diffs, we get higher tls index value which cannot be expressed using addressing mode and hence couldn't be eliminated.
@@ -1060,6 +1068,14 @@ bool Compiler::fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* | |||
// Create tree to "threadStaticBlockValue = threadStaticBlockBase[typeIndex]" | |||
typeThreadStaticBlockIndexValue = gtNewOperNode(GT_MUL, TYP_INT, gtCloneExpr(typeThreadStaticBlockIndexValue), | |||
gtNewIconNode(TARGET_POINTER_SIZE, TYP_INT)); | |||
// Usually a constant, try to fold | |||
typeThreadStaticBlockIndexValue = gtFoldExpr(typeThreadStaticBlockIndexValue); |
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.
should this be or do we need to fold expression before casting it as well?
#ifdef TARGET_X64
typeThreadStaticBlockIndexValue = gtNewCastNode...
#endif
typeThreadStaticBlockIndexValue = gtFoldExpr(...
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.
We need to fold it before as well since gtFoldExpr
is not recursive.
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
The TLS helper expansion would produce
ADD(long, int)
trees likewhich is not legal IR. Fix that by inserting a cast. Also do some more aggressive folding to get rid of these casts in the normal cases, and to fold some constant arithmetic in other cases.
Noticed this while investigating #108830.