Skip to content

Conversation

@SingleAccretion
Copy link
Contributor

@SingleAccretion SingleAccretion commented May 4, 2022

When creating address modes, we try to look through cascading ADDs with constants that could contribute to the final displacement (LEAs "offset"). In doing so, we were failing to take into account the possibility that said constants could be relocatable handles, such as [000016] in the following tree:

N009 (  9, 11) [000009] ---XG------                         *  RETURN    int
N008 (  8, 10) [000008] ---XG------                         \--*  IND       ushort
N007 (  5,  8) [000007] -------N---                            \--*  ADD       byref
N003 (  3,  6) [000015] -----------                               +--*  ADD       byref
N001 (  1,  1) [000014] -----------                               |  +--*  CNS_INT   long   12 field offset Fseq[_firstChar]
N002 (  1,  4) [000016] H----------                               |  \--*  CNS_INT(h) ref    0x420068 [ICON_STR_HDL]
N006 (  2,  2) [000006] -------N---                               \--*  LSH       long
N004 (  1,  1) [000003] -----------                                  +--*  LCL_VAR   long   V00 arg0         u:1 (last use)
N005 (  1,  1) [000005] -----------                                  \--*  CNS_INT   long   1

We cannot fold such "constants" into LEAs, this change makes the address mode forming logic respect that.

Should fix the crashes seen in #68739.

No diffs are expected.

The code in "genCreateAddrMode" was performing the equivalent of constant
folding ADDs, but failing to take into account the legality of doing that.
@ghost ghost added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member labels May 4, 2022
@ghost
Copy link

ghost commented May 4, 2022

Tagging subscribers to this area: @JulieLeeMSFT
See info in area-owners.md if you want to be subscribed.

Issue Details

When creating address modes, we try to look through cascading ADDs with constants that could contribute to the final displacement (LEAs "offset"). In doing so, we were failing to take into account the possibility that said constants could be relocatable handles, such as [000016] in the following tree:

N009 (  9, 11) [000009] ---XG------                         *  RETURN    int
N008 (  8, 10) [000008] ---XG------                         \--*  IND       ushort
N007 (  5,  8) [000007] -------N---                            \--*  ADD       byref
N003 (  3,  6) [000015] -----------                               +--*  ADD       byref
N001 (  1,  1) [000014] -----------                               |  +--*  CNS_INT   long   12 field offset Fseq[_firstChar]
N002 (  1,  4) [000016] H----------                               |  \--*  CNS_INT(h) ref    0x420068 [ICON_STR_HDL]
N006 (  2,  2) [000006] -------N---                               \--*  LSH       long
N004 (  1,  1) [000003] -----------                                  +--*  LCL_VAR   long   V00 arg0         u:1 (last use)
N005 (  1,  1) [000005] -----------                                  \--*  CNS_INT   long   1

We cannot fold such "constants" into LEAs, this change makes the address forming logic respect that.

Should fix the crashes seen in #68739.

No diffs are expected.

Author: SingleAccretion
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@SingleAccretion SingleAccretion force-pushed the Fix-genCreateAddrMode-Handles branch from 3bc12e4 to 8a9d859 Compare May 5, 2022 15:36
@SingleAccretion SingleAccretion marked this pull request as ready for review May 5, 2022 18:07
@SingleAccretion
Copy link
Contributor Author

Diffs.

No code diffs as expected; unfortunately however, there is a throughput impact which I was not able to mitigate. I suppose since we're enabling #68739 (which improves TP significantly) with this correctness fix, that may yet be acceptable.

@dotnet/jit-contrib

Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the TP impact looks insignificant to me.

@SingleAccretion
Copy link
Contributor Author

The Mono AOT failure looks like #57361, presumably exposed by the recently merged #68288:

2022-05-05T18:04:04.8696931Z   aot-compile: compiling /__w/1/s/artifacts/tests/coreclr/Linux.x64.Release/Tests/Core_Root/System.Net.Quic.dll; MONO_PATH: /__w/1/s/artifacts/tests/coreclr/Linux.x64.Release/Tests/Core_Root:/__w/1/s/artifacts/tests/coreclr/Linux.x64.Release/Tests/Core_Root
2022-05-05T18:04:04.9730403Z   Mono Ahead of Time compiler - compiling assembly /__w/1/s/artifacts/tests/coreclr/Linux.x64.Release/Tests/Core_Root/System.Net.Quic.dll
2022-05-05T18:04:04.9734523Z   AOTID E335E44F-900C-EC59-B454-0C7D355FE91C
2022-05-05T18:04:04.9736397Z   * Assertion at /__w/1/s/src/mono/mono/metadata/custom-attrs.c:602, condition `out_obj' not met

@jakobbotsch jakobbotsch merged commit c55b855 into dotnet:main May 5, 2022
@SingleAccretion SingleAccretion deleted the Fix-genCreateAddrMode-Handles branch May 5, 2022 19:40
@ghost ghost locked as resolved and limited conversation to collaborators Jun 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants