Commit Graph
23802 Commits
Author SHA1 Message Date
SingleAccretion b36548cae1 Make field nodes unary (#60105)
* 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.
2021-10-07 10:47:07 -07:00
SingleAccretion 23e386f5b3 Remove dead code (#60095)
* 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 :(.
2021-10-07 10:33:12 -07:00
Kunal Pathak 4eb8d0ebec Fix an assert condition for UpperVectorSave/Restore (#60108)
* expand assert to take save upper vector in account

* jit format
2021-10-07 10:31:38 -07:00
Robin Lindner 6195d98cad Optimize code readability by replacing ternary operator with logical or construct (#60071) 2021-10-07 09:14:03 -06:00
Tomáš Rylek 9e9001812a Add R2RTest support for the perfmap-format-version Crossgen2 option (#60002) 2021-10-07 12:50:49 +02:00
yowl 45fe1dece9 add PreciseRefCountsRequierd to better describe the intention (#60027)
The condition is different in NativeAOT, so this helps downstream.
2021-10-07 10:58:37 +02:00
Jakob Botsch Nielsen 367b006530 Support fast tailcalls in R2R (#56669)
* 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
2021-10-07 10:15:59 +02:00
Jakob Botsch Nielsen a258c4fe6b Fix benign assert in gtNewTempAssign (#59991)
The later part of this method correctly handles the GT_COMMA case, so we
just need to fix the assert.

Fix #59871
2021-10-07 10:15:11 +02:00
Bruce Forstall fd69468ca7 Change loop cloning conditions codegen (#59886)
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.
2021-10-06 22:26:48 -07:00
David Mason 240a64d14c Change profilers to use thread local evacuation counters (#59741)
* 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
2021-10-06 19:59:43 -07:00
Aleksey Kliger (λgeek) b393a43a62 [mono] Implement coreclr_create_delegate and move ComponentActivator to shared CoreLib (#59962)
* [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
2021-10-06 18:52:26 -04:00
Bruce Forstall 3e79767855 Fix win-x64 outgoing argument size calculation for PInvoke prolog helper (#60050)
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
2021-10-06 08:50:50 -07:00
Jan Kotas 62d70c4f79 Use custom error message when running out of syncblocks (#60013)
Contributes to #49215
2021-10-06 05:45:59 -07:00
Theodore Tsirpanis 732ee3c9cd Remove the runtime-specific Stream source files. (#60019)
`Stream.CoreCLR.cs` and `Stream.Mono.cs` were almost identical.
2021-10-05 19:35:11 -07:00
Andy Ayers 26954f5e1d JIT: better support for patchpoints in try regions (#59784)
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.
2021-10-05 18:40:45 -07:00
Andrew Au 64842b50dc Code review feedback for DacHeapWalker (#60014) 2021-10-05 13:28:11 -07:00
Egor Bogatov 9acc383f9a Ignore nop-statements in tc validation (#59980) 2021-10-05 20:02:12 +03:00
SingleAccretion 220b746f1e Implement GT_MUL_LONG for ARM64 (#57926)
* 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
2021-10-05 09:54:45 -07:00
Adeel Mujahid d96100a496 Fix a macro usage and cleanup stale comment (#59907) 2021-10-04 17:50:40 -07:00
Pent Ploompuu 7afb66262c Optimize division by constant after AND or RSZ (#55778)
* Optimize division by constant after AND or RSZ

* Address PR feedback
2021-10-04 13:52:02 -07:00
Egor BogatovandTanner Gooding fcee44ab15 Optimize Vector128/256.Equals via TestZ (#55875)
Co-authored-by: Tanner Gooding <[email protected]>
2021-10-04 22:32:32 +03:00
Egor Bogatov 025c84dd00 Fix genCodeForInitBlkUnroll for x86 (#59873) 2021-10-04 22:19:25 +03:00
Ilia 2d11434892 Fix unmatched transition callback in JIT_ReversePInvokeExitTrackTransitions (#59919)
Fixes #59917
2021-10-04 09:50:53 -07:00
SingleAccretion 6fb5ef73e1 Stop retyping RHSes to byrefs on type mismatch (#58297)
* 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.
2021-10-04 08:14:46 -07:00
Jan Vorlicek 33204f6a09 Fix code heap reservation size (#59883)
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
2021-10-04 09:47:07 +02:00
Michal Strehovský b72b8a2a8c Annotate methods that get MethodBase from a stackwalk as RUC (#59851)
Fixes #53242. Saddened this didn't make .NET 6.0.

Stack traces in trimmed apps look ugly without this fix:

```
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'id')
   at System.TimeZoneInfo.ValidateTimeZoneInfo(String , TimeSpan , AdjustmentRule[] , Boolean& )
   at System.TimeZoneInfo..ctor(String , TimeSpan , String , String , String , AdjustmentRule[] , Boolean , Boolean )
   at System.TimeZoneInfo.CreateCustomTimeZone(String , TimeSpan , String , String )
   at Program.<Main>$(String[] args) in C:\stacktrace\Program.cs:line 3
```
2021-10-04 15:18:55 +09:00
Jakob Botsch Nielsen 911944dda2 Clean up fix for single-reg returned normalize-on-load vars (#59645)
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.
2021-10-02 13:13:09 +02:00
Egor Bogatov 25afc59af4 fix resolveVirtualMethodHelper (#59742) 2021-10-02 12:54:02 +03:00
Michal Strehovský 7af224e8d9 Move MakeReproPackage logic to a shared location (#59796)
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.
2021-10-02 12:32:54 +09:00
Kunal Pathak 4963df91bd Arm64: Align methods containing loops to 32B (#59828)
* Fix an assert and tighter check for arm64 misestimation

* Align methods at 32B
2021-09-30 22:10:28 -07:00
Theodore Tsirpanis 4ddd11dd62 Use the short form of an opcode in ILGenerator.EmitWriteLine. (#59836)
`ILGenerator.Emit(short)` does not use short forms if applicable; only the int overload does, but here we can directly use `ldarg.0`.
2021-09-30 18:53:21 -07:00
Jan Vorlicek 900a0d62df Fix Unix ARM64 RtlRestoreContext implementation (#59831)
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.
2021-09-30 18:36:05 -07:00
Andy Ayers 646e1952e6 JIT: fix register arg size computation for OSR (#59789)
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.
2021-09-30 18:00:03 -07:00
826f49dd60 Expose cross-platform helpers for Vector64, Vector128, and Vector256 (#53450)
* 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]>
2021-09-30 16:27:06 -07:00
SingleAccretion d500e00219 Refactor fgMorphCast (#59713)
* 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.
2021-09-30 13:43:04 -07:00
SingleAccretion 38e28fb458 Leverage cwde and cdqe for sign extensions on xarch (#56172)
* 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.
2021-09-30 09:34:37 -07:00
Egor Bogatov d7b9db91ec Fix assert for chain of ASG nodes after tail-calls (#59708) 2021-09-30 16:47:54 +03:00
David Wrighton 5e5a1bd137 Fix issue with incorrect handling of optimized method layouts (#59781)
- 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
2021-09-29 17:58:12 -07:00
Tomáš Rylek a8da5113f9 Fix for GitHub issue #59432 and the corresponding regression test (#59663)
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
2021-09-30 02:15:19 +02:00
Andrew Au 32a976be1d Avoid resetting gen0 bricks for background_sweep (#59106) 2021-09-29 16:44:28 -07:00
Kunal Pathak cf5c6a436c Do not enregister Return SP check (#59759) 2021-09-29 16:41:53 -07:00
Egor Chesakov cd1cd1d2be Fix several issues with ELT profiler hooks and tests to cover these cases (#54912)
* 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.
2021-09-29 14:35:54 -07:00
Kunal Pathak e4a842ea73 Arm: Include BBJ_ALWAYS blocks in dominance calculation (#59376)
* Include BBJ_ALWAYS in inverse post ordering for computing reachability

* Add test case

* Add BBJ_ALWAYS in fgAlways list

* jit format
2021-09-29 07:49:55 -07:00
Adeel Mujahid 70b03114f4 Append _FILE_OFFSET_BITS=64 to CMAKE_REQUIRED_DEFINITIONS (#59504)
After setting CMAKE_REQUIRED_DEFINITIONS in PAL introspection, we need
to append this definition.
2021-09-29 10:42:35 +02:00
Michal Strehovský d4e85bf268 Integrate changes from NativeAOT branch (#59510)
* Move TryResolveConstraintMethodApprox to compiler

* Integrate changes from NativeAOT branch
2021-09-28 23:10:44 -07:00
Kunal Pathak 8adff3497b Antigen: Change Antigen's helixqueue to public (#59657)
* 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
2021-09-28 19:51:48 -07:00
David Wrighton fcaba18061 Universal arm crossgen compiler (#58279)
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)
2021-09-28 16:52:10 -07:00
David Wrighton fcde5f6d2a Add Compiler record to PDB files in Crossgen2 (#59686) 2021-09-28 13:51:45 -07:00
Andy Ayers be752825a4 JIT: allow suppressing some dumps or parts of dumps (#59299)
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.
2021-09-28 09:16:42 -07:00
Sergey Andreenko 181da3bd9c Fewer AddressExposedReason::TOO_CONSERVATIVE (#59429)
Delete some too_conservative addrExposed reasons.
2021-09-28 14:45:36 +02:00