Value number TypeHandleToRuntimeType helper#9560
Conversation
This is a pure helper w/o side-effects, so add it to the lists of tractable helpers in value-numbering; this allows redundant calls to be CSEd, and fixes #9552 so we can again optimize away type checks on type parameters in generic code (a not-infrequent pattern).
|
@AndyAyersMS @briansull @dotnet/jit-contrib PTAL. |
|
Do we know for sure it is pure? Or is it only pure for the special cases that the pattern match was getting? Would like to see if you get any diffs from this in jit-diff. |
It looks to me like the pattern-match is happy with any Maybe @jkotas or @davidwrighton or someone can answer more authoritatively: is it safe for the JIT to always assume that |
Yes. It can throw out-of-memory - but it should not stop you from treating it as pure and side-effect free. |
|
Should the relevant morph code be deleted? |
|
@dotnet-bot test OSX x64 Checked Build and Test |
I would recommend leaving the code in morph if @AndyAyersMS's pending work makes it effective again, as it may be useful during scenarios that do not run with the SSA-based optimizer enabled. |
@AndyAyersMS indicated that he's planning to update the importer in a way that the morph code would again be catching most (all?) of these changes. My thinking is the redundancy isn't much of a maintenance or throughput concern, so may as well have the morph code to snip out most cases early and the value numbering to pick up any stragglers or new/different patterns. |
|
Yeah, I think we should do both; the space & size savings are significant and the morph pattern kicks in unconditionally, and it's pretty cheap (in terms of jit time) to recognize. The less code the optimizer has to look at the better. Will be interesting to see if the VN approach finds any additional instances. |
I do, but if any of them are from optimizing away this sort of compare, they get drowned out because most/all diffs are straight CSEs of redundant calls to this helper, not on two sides of a compare. Here's the jit-analyze output:
Presumably these CSE cases get past the compare-centric morph optimization. |
|
Above data is from running on top of #9562... ? |
|
Do we have any tests to help catch regressions in this kind of thing in the future? |
|
For code size and such there is manual testing available via jit-diff; in fact I ran it for #7923 and commented as such in the PR. We usually ask jit devs to post this data. Evidently I did something wrong when I ran the tests. |
No, running before that got merged. |
|
The data I get on top of #9562: |
|
Diffs in object result = null;
RuntimeType t = (RuntimeType)typeof(T);
// Specialize type byte for performance reasons
if (t == typeof(byte)) {
result = new ByteEqualityComparer();
}The code author likely thought hosting BTW the generated code -- while vastly simpler -- still looks overly complex to me... |
Value number TypeHandleToRuntimeType helper Commit migrated from dotnet/coreclr@539b142
This is a pure helper w/o side-effects, so add it to the lists of
tractable helpers in value-numbering; this allows redundant calls to be
CSEd, and fixes #9552 so we can again optimize away type checks on type
parameters in generic code (a not-infrequent pattern).