-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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: Fold unreachable cases for switch in importer. #82793
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak Issue DetailsDraft PR.
|
@JulieLeeMSFT is this ready for review? |
Diffs show some unexpected size increases, eg
Can you investigate? Also some diffs in minopts which we probably don't want. |
Yes, I am working on it.
|
src/coreclr/jit/importer.cpp
Outdated
/* Pop the switch value off the stack */ | ||
op1 = impPopStack().val; | ||
assertImp(genActualTypeIsIntOrI(op1->TypeGet())); | ||
|
||
/* We can create a switch node */ | ||
// Fold Switch for GT_CNS_INT | ||
if ((op1->gtOper == GT_CNS_INT) && !compIsForImportOnly()) |
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.
if ((op1->gtOper == GT_CNS_INT) && !compIsForImportOnly()) | |
if (opts.OptimizationEnabled() && (op1->gtOper == GT_CNS_INT) && !compIsForImportOnly()) |
We don't want to do this unless we're optimizing the method.
This should fix the diffs you are seeing with minopts.
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.
Done.
/* Pop the switch value off the stack */ | ||
op1 = impPopStack().val; | ||
assertImp(genActualTypeIsIntOrI(op1->TypeGet())); | ||
|
||
/* We can create a switch node */ | ||
// Fold Switch for GT_CNS_INT |
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.
You should try constant-folding the op1
here, to increase the number of times we see constants.
op1 = gtFoldExpr(impPopStack().val);
(replace line 8004 above)
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.
Done.
src/coreclr/jit/importer.cpp
Outdated
printf(" to " FMT_BB, block->bbJumpDest->bbNum); | ||
} | ||
printf("\n"); | ||
fgDispBasicBlocks(true); |
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 probably don't need to show all BBs 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.
Removed.
… resolve regression in minopts.
|
@AndyAyersMS, it is ready for review. |
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 good!
This PR folds unreachable cases in Switch early in
Import
phase when switch value is GT_CNT_INT.Fixes #65368.
Below trees show the optimization example for the below scenario: