-
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
Fold null checks against known non-null values #109164
base: main
Are you sure you want to change the base?
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
@MihuBot -dependsOn 108579 |
src/coreclr/jit/gentree.cpp
Outdated
|
||
return NewMorphedIntConNode(compareResult); | ||
GenTree* newTree = gtNewIconNode(compareResult); | ||
if (wrapEffects) |
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.
just wrap unconditionally, gtWrapWithSideEffects
won't create a COMMA if there are no side-effects
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.
AFAIR we can't use the op
if gtTryRemoveBoxUpstreamEffects
removes the box, that's why I did the check.
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.
not sure I understand, if it removes - does it leave a tree with a side-effect?
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.
not sure I understand, if it removes - does it leave a tree with a side-effect?
As far as @SingleAccretion explained it to me on Discord, using the tree when gtTryRemoveBoxUpstreamEffects
succeedes is nonsensical since the original tree is invalid due to the earlier box not existing anymore.
src/coreclr/jit/gentree.cpp
Outdated
GenTree* boxSourceTree = gtTryRemoveBoxUpstreamEffects(op); | ||
bool didOptimize = (boxSourceTree != nullptr); | ||
// See if we can optimize away the box and related statements. | ||
wrapEffects = (gtTryRemoveBoxUpstreamEffects(op) == nullptr); |
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.
previous logic used to give up if box can't be removed, is it expected that the new one always folds?
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.
btw, does it all handle boxed nullables (when boxed value is null reference)?
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.
is it expected that the new one always folds?
Yeah, my reasoning here was that there's no reason to avoid folding if we can't remove.
does it all handle boxed nullables (when boxed value is null reference)?
Not sure, I'd assume those wouldn't pass IsBoxedValue
, otherwise I'd think the previous code would be broken.
EDIT: They wouldn't, IsBoxedValue
checks GTF_BOX_VALUE
which guarantees it's not null.
@MihuBot -dependsOn 109715 |
Found in #108579.