Skip to content

Do not fold relocatable constants into displacements - #68851

Merged
jakobbotsch merged 2 commits into
dotnet:mainfrom
SingleAccretion:Fix-genCreateAddrMode-Handles
May 5, 2022
Merged

Do not fold relocatable constants into displacements#68851
jakobbotsch merged 2 commits into
dotnet:mainfrom
SingleAccretion:Fix-genCreateAddrMode-Handles

Conversation

@SingleAccretion

@SingleAccretionSingleAccretion commented May 4, 2022

Copy link
Copy Markdown
Contributor

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.
@ghostghost 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

ghost commented May 4, 2022

Copy link
Copy Markdown

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
SingleAccretionforce-pushed the Fix-genCreateAddrMode-Handles branch from 3bc12e4 to 8a9d859CompareMay 5, 2022 15:36
@SingleAccretion
SingleAccretion marked this pull request as ready for review May 5, 2022 18:07
@SingleAccretion

Copy link
Copy Markdown
ContributorAuthor

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

@jakobbotschjakobbotsch left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
ContributorAuthor

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:mainMay 5, 2022
@SingleAccretion
SingleAccretion deleted the Fix-genCreateAddrMode-Handles branch May 5, 2022 19:40
@ghostghost locked as resolved and limited conversation to collaborators Jun 5, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates 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

@SingleAccretion@jakobbotsch