Repository navigation
[NOMERGE] Attempt to simplify slice bounds - #136739
NinoFloris wants to merge 8 commits into
Conversation
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @dotnet/area-system-runtime |
|
@EgorBo diffs with the ifdefs removed stay identical to the positive diffs in #136738 (https://dev.azure.com/dnceng-public/public/_build/results?buildId=1656969&view=ms.vss-build-web.run-extensions-tab) We can make the switch. |
SPMI doesn't show diffs for changes in C# |
Ah right... How often do the collections get refreshed again? (just for my understanding when it would show up in the perf tracking even, if this was merged hypothetically) |
I don't think that C# change can be merged, I expect quite a lot of regressions from that still |
|
It did look good locally. I did do some jitdisasms and a few fresh PMI runs against ~100k methods (corelib and some libraries). |
|
Looking at the diffs - nothing changed since the last time I tried, still quite a lot of regressions ( |
Reduce unused instance FIELD_ADDR and ARR_LENGTH nodes to their receiver null checks during side-effect extraction, sharing the existing GetType handling and preserving operand evaluation. This lets local morph discard checks on known local addresses before they cause address exposure. Add Slice bounds-check and unused-length codegen coverage, along with null-exception tests.
Use the existing subtraction-based checks on all architectures for Span and Memory construction and slicing, Memory span access, string span and memory conversion, Substring, and TryGetSpan. Align ValueListBuilder.AppendSpan with the same guard so that its subsequent Slice can reuse the bounds facts.
CSE can give a copy source a new conservative value number while existing copies retain their old identities. Follow same-typed SSA copies when checking non-null assertions, including explicit comparisons against null. Preserve existing VNs so comparisons and range assertions remain consistent. Add coverage for a captured List.Count followed by an inlined Add, where rewriting the copy VN previously prevented bounds-check elimination.
Treat address-exposed local reads as memory-load candidates, using the existing byref-exposed memory value numbers and CSE availability checks. Capture repeated reads in SSA temporaries so subsequent assertions can reuse their values.
Use the existing tree splitter to evaluate the first comparison's operands before combining the tests. This exposes pure comparisons when CSE embeds a definition in the first test, while retaining the second test's side-effect and cost restrictions.
35ff71f to
a7882c2
Compare
|
I should have used more local PMI coverage to diff against before claiming it was OK, but it looks worse than it is. My late night mistake. I have pushed a few more changes, explained below. With these changes, my local ARM64 PMI run shows 4,078 smaller methods versus 2,833 larger, with roughly 31 KB less code overall. About 92% of regressed methods grow by at most 16 bytes, mostly in cases where both bounds comparisons survive in the generated code. @EgorBo what cost/benefit threshold would you use for this change? Do you consider JIT support for transforming checks back into a widened addition a prerequisite for merging? Transforming the checks into the widened-add form in a later phase wouldn’t undo the effects of suboptimal handling in earlier phases, so we'd need everything then. First off, a missed check in StringBuilder.Append, which needs to match the new Slice check. A substantial source of the chunkier code size regressions. Once synced, the sizes for regressions in e.g. runtime/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs Lines 691 to 695 in 591622c After investigating the regressions, most fall into these categories:
Two more CSE related issues surfaced only after those initial CSE fixes:
I have included all these opts into this PR for diff verification only. |
CSE can change a method-table load's receiver VN while the cached load VN still describes the original receiver. Consult the receiver of the defining load as well when matching exact-type assertions, preserving existing VNs. This removes redundant type checks and unboxing fallbacks after successful pattern tests on captured address-exposed locals. Add codegen coverage and verify that replacing the boxed value still requires a checked unbox.
a7882c2 to
17d43d5
Compare
Based on #136738
mostly wondering about diffs.