* Make GenTreeField a unary op
There is no reason for it to be a GTK_SPECIAL op, a concept that
is needed only for nodes with special operand iteration semantics.
There is a quirk in this change, in gtCloneExpr, it is needed to
make this commit a zero-diff one (which it is).
* Remove the quirk
The old implementation of cloning for fields had
an interesting hidden pessimization in it: it set
GTF_GLOB_REF unnecessarily on the cloned tree, even
if the original tree did not have the flag.
This was because "gtNewFldRef", when passed "nullptr"
for the "FldObj", added the aforementioned GTF_GLOB_REF
to the node, presuming it was a static field access.
But we do not need to do that, and this commits removes
the quirk, getting some good diffs in the process.
* Remove dead code
- Delete unused GTF_NOP_DEATH.
- Delete dead code handling GT_INDEX_ADDR as a
GTK_SPECIAL node, it has always been GTK_BINOP.
- Remove the unused Compiler* parameter from GenTreeQmark's constructor.
- Remove the unused Compiler* parameter from LIR::Use::ReplaceWith,
ever so slightly improving its performance.
There are a handful of expected diffs with this change,
they are due to proper costing for INDEX_ADDR causing
fgMorphArgs to make slightly different decisions.
* Use more strong typing in GenTreeQmark
* Call the base constructor
MSVC apparently does not detect this :(.
* Support fast tailcalls in R2R
Partially addresses #5857
* Support ARM64
* Run jit-format
* Fix non-R2R ARM build
* Fix recursive-call-to-loop optimization with non-standard args
* Implement new delay load helper for fast tailcalls
* Minor changes and fix build break
* Switch to a define for tailcall register
* Fix x86
* Implement DefType.IsUnsafeValueType
* Emit rex.jmp for tailcall jumps on x64
* Refactor non standard args + refix recursive tailcall opt
* Set nonStandardArgKind for stack args also
* Regenerate JIT interface
* Improve recursion-to-loop decision about which args need to be reassigned
* Use INS_tail_i_jmp for func token indir
* More efficient arm64 VSD fast tailcalls, fix some bad merging
Also fix logic since we removed tailcall register. For ARM64 that means
we now use the single temp reg that is available for R2R/VSD calls, and
in LSRA we ensure this goes into a volatile register.
* Take R2R indirection into account for tail call profitability
On x64 an R2R indirected direct call normally disassembles the call site
to determine the indirection cell, so it is more expensive to do tail
calls in this scenario as the indirection cell needs to be passed in a
register. Take this into account: if there is no tail. prefix, do normal
calls, and otherwise use tail calls.
* Disallow tailcalls via JIT helper in R2R builds
* Revert "Take R2R indirection into account for tail call profitability"
This reverts commit 863ad4d344bcdacebb00c8c921c7345fd63c7d7b.
Let's not divert on the behavior here. It is not clear that having a
smaller call site is better than tail calling albeit with a larger call
site.
* Add SPMI support, clean up mcPackets enum
* Take necessary conditions into account in canTailCall
Do not do implicit tailcalls when
* The caller is the entry point
* The caller is marked NoInline
* The callee requires security object
Add an option, statically determined at compile time,
to generate loop cloning loop choice conditions into one block
per condition instead of using bitwise `and` operators that
execute all non-dependent conditions in a single block. Set the
condition to use the one-block-per-condition mode.
This leads to code size reduction in the generated condition code,
generally performance improvements in the microbenchmarks,
as well as making it easier to understand.
* Change profilers to use thread local evacuation counters
Change to prefix increment
* get rid of lambdas
* Fix jit inlining, fix R2R too
* Remove VolatilePtr<> from helpers
* Get rid of additionalData argument
* [CoreLib] Move ComponentActivator to the shared area
* [mono] Implement coreclr_create_delegate hosting API
Related to https://github.com/dotnet/runtime/issues/59815
* Mark IsolatedComponentLoadContext as unsupported on mobile and browser
Should make ComponentActivator work without them (depends on AssemblyDependencyResolver, which depends on hostpolicy or hostpolicy pinvoke redirects)
* Also unsupported on MacCatalyst
The win-x64 ABI requires allocating 32 bytes of outgoing argument
stack space for every call, which can be used by callees. In the case
where there are no calls in a function, there is no need to allocate
that space. The JIT computes the required argument space during
`fgSimpleLowering` by processing the IR and looking for call instructions,
but also accounting for a few special cases where calls are not visible
in the IR. One case was missing, leading to a zero-sized outgoing argument
space even though a call was still generated. This can cause corruption in the
caller stack frame. The case is where there are no explicit calls but the
JIT is going to generate a PInvoke frame initialization helper call. This
shouldn't happen, however, it occurs because the JIT eliminates a PInvoke
that is statically dead code, but still generates the prolog setup code.
A general solution would be to eliminate the PInvoke setup code if there
are no remaining PInvokes in the function. The simple change made here is
to ensure there is sufficient outgoing argument space for the PInvoke helper
call if that will be generated.
This was found by seeing test crashes due to stack corruption when
building the CLR with the VC++ compiler `-O2` optimization switch, which
stored data in the incoming argument stack space of the PInvoke helper function
(with PR https://github.com/dotnet/runtime/pull/59235).
There are 5 SPMI diffs: 2 in coreclr tests (the ones that failed at runtime),
2 in libraries tests, and 1 in System.Net.Http.WinHttpChannelBinding:.ctor(SafeWinHttpHandle):this
This change adds control flow to ensure that an OSR method for a patchpoint
nested in try regions enters those regions try from the first block of each
try rather than mid-try.
This lets these OSR methods conform to the data flow expectations that the
only way control flow can enter a try is via its first block.
See #33658 for more details on the approach taken here.
Fixes#35687.
* Refactor LONG_MUL recognition
Move it to a GenTree method so that it can be reused in lowering.
No diffs except for a couple (~5 across all SPMI collection) on
ARM due to the new operand swapping behavior.
* Fix the definition for MUL_LONG
Move it out of the "#if !defined(TARGET_64BIT)" block.
Also some miscellaneous moving of comments around.
* Support MUL_LONG for ARM64 in codegen and LSRA
Note: this commit breaks magic division.
* Fix magic division
To use the new GT_MUL_LONG support.
Plus some tweaks to make it conform to the coding guide.
Credit to @pentp for the substantive changes.
* Recognize MUL_LONG in lowering for ARM64
* Fix #ifdef's
* Stop retyping RHSes to byrefs on type mismatch
This is an interesting piece of code. Using it, it is possible
to give TYP_BYREF to any node that would ordinarily have
TYP_I_IMPL. In particular, I encountered it in my GT_CAST work:
we have tests in the SPMI collections with CAST(byref <- long <- int)
in them. Ordinarily such a tree would assert in VN, but in that
case optimizations were off and so everything went smoothly.
It is possible to have TYP_BYREF UMOD/MUL_OVF_UN and similar
with this code. Naturally, even though this is legal IL, the
compiler does not like it and fails with asserts in multiple
places.
So, just delete the retyping. The cited assert either no longer
exists (though I had a look at the legacy codegen and could not
find it there...) or got reworked at some point.
There are GC Info diffs with this change. They consist of cases
when a constant zero node was retyped to TYP_BYREF and thus its
register's liveness was recorded.
There are few code size diffs with this change. It does pessimize VN
a little because we will now have more cases where a cast VN is added
for an assignment, but VN is already very pessimistic for byrefs, so
it seems acceptable.
* Add a test covering the discovered problem
VN-based copy propagation checks the compatibility of types using
the type of node at use and the RHS of the new local's def. Thus,
when we retype a TYP_I_IMPL RHS to TYP_BYREF, we risk substituting a
TYP_BYREF local with a TYP_I_IMPL one, dangerously shortening the
lifetime of the managed pointer.
When I've moved the heap metadata out of the actual code heaps some time
ago, I've forgotten to account for the personality routine slot
allocated at the beginning of the heaps. This was exposed by an assert when
executing under the JIT stress mode 2.
This change fixes it by adding accounting for those.
Close#59794
This is a better fix for #58373 that changes the handling of this to
happen in morph for all cases. We sometimes missed the insertion of
necessary casts because we forgot to remove a GTF_DONT_CSE flag when
folding an indirection. Fixing this leads to some new GT_CNS_DBL cases
in lowering that hit an assert, but those cases should be correctly
handled by the default case so just remove the assert.
To get rid of some of the regressions I have allowed generating
assertions when assigning struct fields from casts. It was unclear why
this was not allowed in the first place.
The move was pretty straightforward and I didn't really need to touch anything.
The only changes I made:
* crossgen2command.txt is now command.txt
* crossgen2repro.rsp is now repro.rsp
* Instead of "CrossGen2 version" the TXT file now says "Compiler version". What compiler will be obvious from the file name and version strings.
The RtlRestoreContext sets SP before reading out PC from the
context. That can lead to a corruption of the PC in the context
if an async signal is delivered to the thread or the thread is
interrupted by any other mean after the SP is set and before
the value of PC is extracted from the context.
This change fixes it by setting the SP after both PC and SP values
are read from the context data structure.
OSR methods must do special setups for register parameters, loading them
from the original method's frame. Update the computation we do here so it
works for TYP_STRUCT register params.
Closes#59875.
* Refactoring Vector<T> to be alphabetically ordered and reduce duplicated code
* Adding a debug view to System.Numerics.Vector<T>
* Do some basic code cleanup and refactoring of Vector64/128/256
* Updating Vector64/128/256 to expose cross platform helper methods
* Adding templated tests for Vector64
* Regenerating templated tests for Vector64
* Adding templated tests for Vector128
* Regenerating templated tests for Vector128
* Adding templated tests for Vector256
* Regenerating templated tests for Vector256
* Fix getSIMDStructFromField to account for accessing the private ulong fields for Vector64/128/256<T>
* Ensure helper intrinsics don't insert on importation
* Minor cleanup of impBaseIntrinsic for x86/x64
* Intrinsify the Vector64/128/256 methods
* Make the internal helper named IsTypeSupported to not conflict with mono's existing check
* Ensure we lie about the type for TYP_SIMD32 bitwise ops when only AVX is supported
* Use gtNewSimdZeroNode rather than gtNewSIMDVectorZero
* Applying formatting patch
* Apply suggestions from code review
Co-authored-by: SingleAccretion <[email protected]>
* Apply suggestions from code review
* Split HardwareIntrinsic tests into 3 groups
* Update src/coreclr/vm/class.cpp
Co-authored-by: Egor Chesakov <[email protected]>
Co-authored-by: SingleAccretion <[email protected]>
Co-authored-by: Egor Chesakov <[email protected]>
* Split and rework fgMorphCast
Split it into the part that does pre-order transforms
and the part that does post-order optimizations.
Rename the pre-order part to "fgMorphExpandCast" and let
"fgMorphSmpOp" do the morphing of operands and optimization.
Just one diff for this commit: "gtFoldExprConst" does not
retain the types of handles, thus LSRA was not seeing
"long" and "byref" constant integers with the same values as
equivalent and did not reuse the register.
* Delete unneeded code from "fgOptimizeCast"
These cases are now covered by "fgMorphSmpOp".
* Refactor comma throw propagation
So that it works well for casts.
There are diffs for this commit in the ILGEN methods,
mostly positive, but some are regressions.
The regressions fall into 2 buckets:
1. The new code creates overflow helper blocks for casts
before propagating comma throws, thus leaving them
around, dead. This is a problem in general and should
be solved by moving the helper insertion later.
2. The new code doesn't propagate comma throws after global
morph for casts. This is is by design, as the throw
propagation does not work well with VNs (and CSE).
The improvements are due to new code setting "fgRemoveRestOfBlock"
for comma throws originating from casts.
* Add CWDE support to the emitter and codegen
It is a shorter form of a sign extending mov from eax to eax.
Use it in codegen for casts.
* Fix printing for CWDE and CDQ
Their size determines what they do.
* Move the optimization to emit_Mov
This allows us to catch more cases.
- The sort order of the RuntimeFunctions table (among others) was not properly handled when an optimized method layout was applied
- While this bug applied to non-composite builds, it was easily reproduced with a composite build
- Fix lack of test infrastructure around non-standard method layouts.
- Add new random method sorting order
- Use new random sorting order in crossgen2 test passes
Fixes#59089
Turns out there was a subtle bug in the interface slot map population
that got triggered by a suitable combination of non-virtual and
virtual interface methods.
Thanks
Tomas
* Add ELT profiler tests for HFA/HVA arguments/return values on Arm64.
* Fix an issue with `ProfileArgIterator::GetNextArgAddr` and `ProfileArgIterator::GetReturnBufferAddr` not properly handling HFA/HVAs on Arm64.
* Add tests to cover different ways of returning a struct on Linux x64 and macOS x64 (i.e. one register, two registers, stack).
* Fix an issue with `ProfileArgIterator::GetReturnBufferAddr` not properly handling struct returned in registers on Linux x64 and macOS x64.
* Fix an issue with not passing an actual value of `rdx` down to a callback in `ProfileLeaveNaked` and `ProfileTailcallNaked` helpers.
* Use public helix queue
* Remove helix queue setup from python
* Remove unnecessary comments
* TOREVERT: Download specific artifacts
* change creator to dotnet-bot
* set Creator
* run only for windows x64
* Publish antigen build logs
* put in quotes
* use correct script for helix queue
* Set some helix variables:
* Use Helix properties in proj
* Include the display name
* Revert specific build
* Add continueOnError to display warnings
Stop generating OS specific compilers for the arm and arm64 architectures for use in crossgen2
- As it turns out the OS differences here are relatively minor and fairly easy to handle with runtime switches.
- However, when an exact target is known we can generate better code by having the various if statements evaluate to a constant true/false. (This is done for all runtime jit builds)
- This has been validated to produce binary identical output for generating System.Private.CoreLib.dll on the various architectures.
- This work reduces the distribution size of crossgen2, and also reduces the amount of time it takes to build everything (Most notably, the Mac build times in PR's are reduced by 5-7 minutes, but improvements are visible across all of/architecture pairs)
Another bit of code that I've had lying around that might be generally useful.
* Optionally suppress Tier0 compilation dumps
* Optionally suppress dumps from inline compiler phases
Setting `JitDumpTier0=0` prevents you from getting two dumps when you specify
dumping a method by name or hash, when TC is enabled.