Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set some missing GTF_GLOB_REF and improve its checking. #61245

Closed
wants to merge 4 commits into from

Conversation

sandreenko
Copy link
Contributor

@sandreenko sandreenko commented Nov 5, 2021

The code in fgDebugCheckFlags had some mistakes that were easy to fix, for harder errors I added a comment explaining them.

The diff is a regression but a small one.

The diffs look like correctness fixes, for example, for such comparison:

Core_Root\superpmi.exe "Core_Root_base\clrjit.dll" "Core_Root_diff\clrjit.dll" D:\Sergey\git\runtime\artifacts\spmi\mch\3df3e3ec-b1f6-4e6d-8439-2e7f3f7fa2ac.windows.x64\libraries_tests.pmi.windows.x64.checked.mch  -a -c 78772

we forbid swapping call and IND(global static field), if I understand correctly, nothing prevents the call from making a change in this field, so it should not be hard to create a correctness repro for this bug.

***** BB01
++STMT00002 (IL   ???...  ???)
++               [000013] -A--G-------              *  ASG       byref 
++               [000012] D------N----              +--*  LCL_VAR   byref  V03 tmp2         
++               [000003] ----G-------              \--*  ADD       byref 
++               [000001] n---G-------                 +--*  IND       ref   
++               [000000] I-----------                 |  \--*  CNS_INT(h) long   0xd1ffab1e static Fseq[hackishFieldName]
++               [000002] ------------                 \--*  CNS_INT   long   8 Fseq[#FirstElem]
***** BB01
STMT00001 (IL   ???...  ???)
               [000011] I-C-G-------              *  CALL      void   System.TimeSpan..ctor (exactContextHnd=0x00000000D1FFAB1E)
               [000010] ------------ this in rcx  +--*  ADDR      byref 
               [000009] -------N----              |  \--*  LCL_VAR   struct<System.TimeSpan, 8> V02 tmp1         
               [000005] ------------ arg1         \--*  CNS_INT   long   1

***** BB01
STMT00002 (IL 0x00C...  ???)
--               [000013] I-C-G-------              *  CALL      struct System.TimeSpan.Add (exactContextHnd=0x00000000D1FFAB1E)
--               [000003] ------------ this in rcx  +--*  ADD       byref 
--               [000001] ------------              |  +--*  IND       ref   
--               [000000] I-----------              |  |  \--*  CNS_INT(h) long   0xd1ffab1e static Fseq[hackishFieldName]
--               [000002] ------------              |  \--*  CNS_INT   long   8 Fseq[#FirstElem]
--               [000015] n----------- arg1         \--*  OBJ       struct<System.TimeSpan, 8>
--               [000014] ------------                 \--*  ADDR      byref 
--               [000012] -------N----                    \--*  LCL_VAR   struct<System.TimeSpan, 8> V02 tmp1 
++STMT00003 (IL 0x00C...  ???)
++               [000016] I-C-G-------              *  CALL      struct System.TimeSpan.Add (exactContextHnd=0x00000000D1FFAB1E)
++               [000014] ------------ this in rcx  +--*  LCL_VAR   byref  V03 tmp2         
++               [000018] n----------- arg1         \--*  OBJ       struct<System.TimeSpan, 8>
++               [000017] ------------                 \--*  ADDR      byref 
++               [000015] -------N----                    \--*  LCL_VAR   struct<System.TimeSpan, 8> V02 tmp1 

so if inside [000011] I-C-G------- * CALL void System.TimeSpan..ctor we change what is stored in

[000001] n---G-------                 +--*  IND       ref   
[000000] I-----------                 |  \--*  CNS_INT(h) long   0xd1ffab1e static Fseq[hackishFieldName]

then before this change, we would read the changed value, not the correct one.

diffs with misleading total numbers Ignore the total diff, see #60124
Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.windows.x64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.windows.x64.checked.4\diff
 Total bytes of delta: -6956 (-0.10 % of base)
 1 total files with Code Size differences (0 improved, 1 regressed), 1 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.windows.x64.checked.5\base D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.windows.x64.checked.5\diff
 Total bytes of delta: -1515 (-0.00 % of base)
 5 total files with Code Size differences (1 improved, 4 regressed), 4 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.windows.x64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.windows.x64.checked.4\diff
 Total bytes of delta: -3695 (-0.01 % of base)
 3 total files with Code Size differences (0 improved, 3 regressed), 2 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.windows.x64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.windows.x64.checked.4\diff
 Total bytes of delta: -21142 (-0.02 % of base)
 19 total files with Code Size differences (2 improved, 17 regressed), 2 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.Linux.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.Linux.arm64.checked.4\diff
 Total bytes of delta: -1332 (-0.00 % of base)
 1 total files with Code Size differences (0 improved, 1 regressed), 3 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.Linux.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.Linux.arm64.checked.4\diff
 Total bytes of delta: -2920 (-0.01 % of base)
 3 total files with Code Size differences (0 improved, 3 regressed), 1 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.Linux.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.Linux.arm64.checked.4\diff
 Total bytes of delta: -20104 (-0.02 % of base)
 17 total files with Code Size differences (0 improved, 17 regressed), 4 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.Linux.x64.checked.5\base D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.Linux.x64.checked.5\diff
 Total bytes of delta: -7003 (-0.08 % of base)
 1 total files with Code Size differences (0 improved, 1 regressed), 0 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.Linux.x64.checked.5\base D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.Linux.x64.checked.5\diff
 Total bytes of delta: -1295 (-0.00 % of base)
 5 total files with Code Size differences (1 improved, 4 regressed), 4 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.Linux.x64.checked.5\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.Linux.x64.checked.5\diff
 Total bytes of delta: -2909 (-0.01 % of base)
 3 total files with Code Size differences (0 improved, 3 regressed), 1 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.Linux.x64.checked.5\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.Linux.x64.checked.5\diff
 Total bytes of delta: -23240 (-0.02 % of base)
 19 total files with Code Size differences (3 improved, 16 regressed), 2 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.windows.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.windows.arm64.checked.4\diff
 Total bytes of delta: -6992 (-0.09 % of base)
 0 total files with Code Size differences (0 improved, 0 regressed), 2 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.windows.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.windows.arm64.checked.4\diff
 Total bytes of delta: -1332 (-0.00 % of base)
 1 total files with Code Size differences (0 improved, 1 regressed), 3 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.windows.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.windows.arm64.checked.4\diff
 Total bytes of delta: -3848 (-0.01 % of base)
 3 total files with Code Size differences (0 improved, 3 regressed), 2 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.windows.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.windows.arm64.checked.4\diff
 Total bytes of delta: -20100 (-0.02 % of base)
 17 total files with Code Size differences (0 improved, 17 regressed), 4 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.windows.x86.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.windows.x86.checked.3\diff
 Total bytes of delta: -4922 (-0.09 % of base)
 0 total files with Code Size differences (0 improved, 0 regressed), 3 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.windows.x86.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.windows.x86.checked.3\diff
 Total bytes of delta: -2182 (-0.00 % of base)
 7 total files with Code Size differences (0 improved, 7 regressed), 6 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.windows.x86.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.windows.x86.checked.3\diff
 Total bytes of delta: -1532 (-0.00 % of base)
 3 total files with Code Size differences (0 improved, 3 regressed), 3 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.windows.x86.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.windows.x86.checked.3\diff
 Total bytes of delta: -18554 (-0.02 % of base)
 8 total files with Code Size differences (0 improved, 8 regressed), 15 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.Linux.arm.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.Linux.arm.checked.3\diff
 Total bytes of delta: -2176 (-0.00 % of base)
 1 total files with Code Size differences (0 improved, 1 regressed), 6 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.Linux.arm.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.Linux.arm.checked.3\diff
 Total bytes of delta: -1016 (-0.00 % of base)
 3 total files with Code Size differences (2 improved, 1 regressed), 2 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.Linux.arm.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.Linux.arm.checked.3\diff
 Total bytes of delta: -27136 (-0.03 % of base)
 8 total files with Code Size differences (0 improved, 8 regressed), 12 unchanged.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 5, 2021
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Nov 5, 2021
@ghost
Copy link

ghost commented Nov 5, 2021

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

Issue Details

The code in fgDebugCheckFlags had some mistakes that were easy to fix, for harder errors I added a comment explaining them.

The diff is a regression but a small one.

The diffs look like correctness fixes, for example, for such comparison:

Core_Root\superpmi.exe "Core_Root_base\clrjit.dll" "Core_Root_diff\clrjit.dll" D:\Sergey\git\runtime\artifacts\spmi\mch\3df3e3ec-b1f6-4e6d-8439-2e7f3f7fa2ac.windows.x64\libraries_tests.pmi.windows.x64.checked.mch  -a -c 78772

we forbid swapping call and IND(global static field), if I understand correctly, nothing prevents the call from making a change in this field, so it should not be hard to create a correctness repro for this bug.

***** BB01
++STMT00002 (IL   ???...  ???)
++               [000013] -A--G-------              *  ASG       byref 
++               [000012] D------N----              +--*  LCL_VAR   byref  V03 tmp2         
++               [000003] ----G-------              \--*  ADD       byref 
++               [000001] n---G-------                 +--*  IND       ref   
++               [000000] I-----------                 |  \--*  CNS_INT(h) long   0xd1ffab1e static Fseq[hackishFieldName]
++               [000002] ------------                 \--*  CNS_INT   long   8 Fseq[#FirstElem]
***** BB01
STMT00001 (IL   ???...  ???)
               [000011] I-C-G-------              *  CALL      void   System.TimeSpan..ctor (exactContextHnd=0x00000000D1FFAB1E)
               [000010] ------------ this in rcx  +--*  ADDR      byref 
               [000009] -------N----              |  \--*  LCL_VAR   struct<System.TimeSpan, 8> V02 tmp1         
               [000005] ------------ arg1         \--*  CNS_INT   long   1

***** BB01
STMT00002 (IL 0x00C...  ???)
--               [000013] I-C-G-------              *  CALL      struct System.TimeSpan.Add (exactContextHnd=0x00000000D1FFAB1E)
--               [000003] ------------ this in rcx  +--*  ADD       byref 
--               [000001] ------------              |  +--*  IND       ref   
--               [000000] I-----------              |  |  \--*  CNS_INT(h) long   0xd1ffab1e static Fseq[hackishFieldName]
--               [000002] ------------              |  \--*  CNS_INT   long   8 Fseq[#FirstElem]
--               [000015] n----------- arg1         \--*  OBJ       struct<System.TimeSpan, 8>
--               [000014] ------------                 \--*  ADDR      byref 
--               [000012] -------N----                    \--*  LCL_VAR   struct<System.TimeSpan, 8> V02 tmp1 
++STMT00003 (IL 0x00C...  ???)
++               [000016] I-C-G-------              *  CALL      struct System.TimeSpan.Add (exactContextHnd=0x00000000D1FFAB1E)
++               [000014] ------------ this in rcx  +--*  LCL_VAR   byref  V03 tmp2         
++               [000018] n----------- arg1         \--*  OBJ       struct<System.TimeSpan, 8>
++               [000017] ------------                 \--*  ADDR      byref 
++               [000015] -------N----                    \--*  LCL_VAR   struct<System.TimeSpan, 8> V02 tmp1 

so if inside [000011] I-C-G------- * CALL void System.TimeSpan..ctor we change what is stored in

[000001] n---G-------                 +--*  IND       ref   
[000000] I-----------                 |  \--*  CNS_INT(h) long   0xd1ffab1e static Fseq[hackishFieldName]

then before this change, we would read the changed value, not the correct one.

diffs with misleading total numbers Ignore the total diff, see #60124 ``` Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.windows.x64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.windows.x64.checked.4\diff Total bytes of delta: -6956 (-0.10 % of base) 1 total files with Code Size differences (0 improved, 1 regressed), 1 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.windows.x64.checked.5\base D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.windows.x64.checked.5\diff
Total bytes of delta: -1515 (-0.00 % of base)
5 total files with Code Size differences (1 improved, 4 regressed), 4 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.windows.x64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.windows.x64.checked.4\diff
Total bytes of delta: -3695 (-0.01 % of base)
3 total files with Code Size differences (0 improved, 3 regressed), 2 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.windows.x64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.windows.x64.checked.4\diff
Total bytes of delta: -21142 (-0.02 % of base)
19 total files with Code Size differences (2 improved, 17 regressed), 2 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.Linux.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.Linux.arm64.checked.4\diff
Total bytes of delta: -1332 (-0.00 % of base)
1 total files with Code Size differences (0 improved, 1 regressed), 3 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.Linux.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.Linux.arm64.checked.4\diff
Total bytes of delta: -2920 (-0.01 % of base)
3 total files with Code Size differences (0 improved, 3 regressed), 1 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.Linux.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.Linux.arm64.checked.4\diff
Total bytes of delta: -20104 (-0.02 % of base)
17 total files with Code Size differences (0 improved, 17 regressed), 4 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.Linux.x64.checked.5\base D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.Linux.x64.checked.5\diff
Total bytes of delta: -7003 (-0.08 % of base)
1 total files with Code Size differences (0 improved, 1 regressed), 0 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.Linux.x64.checked.5\base D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.Linux.x64.checked.5\diff
Total bytes of delta: -1295 (-0.00 % of base)
5 total files with Code Size differences (1 improved, 4 regressed), 4 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.Linux.x64.checked.5\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.Linux.x64.checked.5\diff
Total bytes of delta: -2909 (-0.01 % of base)
3 total files with Code Size differences (0 improved, 3 regressed), 1 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.Linux.x64.checked.5\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.Linux.x64.checked.5\diff
Total bytes of delta: -23240 (-0.02 % of base)
19 total files with Code Size differences (3 improved, 16 regressed), 2 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.windows.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.windows.arm64.checked.4\diff
Total bytes of delta: -6992 (-0.09 % of base)
0 total files with Code Size differences (0 improved, 0 regressed), 2 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.windows.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.windows.arm64.checked.4\diff
Total bytes of delta: -1332 (-0.00 % of base)
1 total files with Code Size differences (0 improved, 1 regressed), 3 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.windows.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.windows.arm64.checked.4\diff
Total bytes of delta: -3848 (-0.01 % of base)
3 total files with Code Size differences (0 improved, 3 regressed), 2 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.windows.arm64.checked.4\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.windows.arm64.checked.4\diff
Total bytes of delta: -20100 (-0.02 % of base)
17 total files with Code Size differences (0 improved, 17 regressed), 4 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.windows.x86.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.benchmarks.run.windows.x86.checked.3\diff
Total bytes of delta: -4922 (-0.09 % of base)
0 total files with Code Size differences (0 improved, 0 regressed), 3 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.windows.x86.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.windows.x86.checked.3\diff
Total bytes of delta: -2182 (-0.00 % of base)
7 total files with Code Size differences (0 improved, 7 regressed), 6 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.windows.x86.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.windows.x86.checked.3\diff
Total bytes of delta: -1532 (-0.00 % of base)
3 total files with Code Size differences (0 improved, 3 regressed), 3 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.windows.x86.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.windows.x86.checked.3\diff
Total bytes of delta: -18554 (-0.02 % of base)
8 total files with Code Size differences (0 improved, 8 regressed), 15 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.Linux.arm.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.coreclr_tests.pmi.Linux.arm.checked.3\diff
Total bytes of delta: -2176 (-0.00 % of base)
1 total files with Code Size differences (0 improved, 1 regressed), 6 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.Linux.arm.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries.pmi.Linux.arm.checked.3\diff
Total bytes of delta: -1016 (-0.00 % of base)
3 total files with Code Size differences (2 improved, 1 regressed), 2 unchanged.

Creating dasm files: D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.Linux.arm.checked.3\base D:\Sergey\git\runtime\artifacts\spmi\asm.libraries_tests.pmi.Linux.arm.checked.3\diff
Total bytes of delta: -27136 (-0.03 % of base)
8 total files with Code Size differences (0 improved, 8 regressed), 12 unchanged.


</details>


<table>
  <tr>
    <th align="left">Author:</th>
    <td>sandreenko</td>
  </tr>
  <tr>
    <th align="left">Assignees:</th>
    <td>-</td>
  </tr>
  <tr>
    <th align="left">Labels:</th>
    <td>

`area-CodeGen-coreclr`

</td>
  </tr>
  <tr>
    <th align="left">Milestone:</th>
    <td>-</td>
  </tr>
</table>
</details>

@sandreenko
Copy link
Contributor Author

Many regressions are caused by the need to spill such reads before inlinings or tail calls, so @jakobbotsch could you please review it?

@SingleAccretion
Copy link
Contributor

SingleAccretion commented Nov 5, 2021

so if inside [000011] I-C-G------- * CALL void System.TimeSpan..ctor we change what is stored in

[000001] n---G------- +--* IND ref
[000000] I----------- | \--* CNS_INT(h) long 0xd1ffab1e static Fseq[hackishFieldName]

Is that a legal thing to do? Since this is a box in which the struct static is stored, it seems like UB if managed code tried to access it in some way.

(Edit: it would be semantically equivalent to mutating the static's address)

// must have it set as well. However, we clear it from the parent in cases
// ADDR(LCL_VAR or CLS_VAR).
if (oper == GT_ADDR && (op1->OperIs(GT_LCL_VAR, GT_CLS_VAR) ||
(op1->OperIs(GT_IND) && op1->AsOp()->gtOp1->OperIs(GT_CLS_VAR_ADDR))))
Copy link
Member

Choose a reason for hiding this comment

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

Is OperIs(GT_CLS_VAR_ADDR) ever true here? AFAIK we only use those opers very late.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, I was adding it to sync with fgDebugCheckFlags but the only moment when we need it after rationalizing (created first GT_CLS_VAR_ADDR) and before lowering (don't call fgDebugCheckStmtsList->fgDebugCheckFlags in LIR). I will delete this change and add a not to why we need it in fgDebugCheckFlags, thanks for catching this.

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.

I'm not super familiar with how these flags are meant to be propagated, maybe someone more familiar from @dotnet/jit-contrib could have another look?

@sandreenko
Copy link
Contributor Author

so if inside [000011] I-C-G------- * CALL void System.TimeSpan..ctor we change what is stored in

[000001] n---G------- +--* IND ref
[000000] I----------- | \--* CNS_INT(h) long 0xd1ffab1e static Fseq[hackishFieldName]

Is that a legal thing to do? Since this is a box in which the struct static is stored, it seems like UB if managed code tried to access it in some way.

(Edit: it would be semantically equivalent to mutating the static's address)

I am not sure, probably @AndyAyersMS could help here.
The flag that we use here is CORINFO_FLG_FIELD_STATIC_IN_HEAP = 0x00000008, // See code:#StaticFields. This static field is in the GC heap as a boxed object and I was under impression that we are accessing a value of a static field with such IL, do you mean that

               [000001] n---G-------                 +--*  IND       ref   
               [000000] I-----------                 |  \--*  CNS_INT(h) long   0xd1ffab1e static Fseq[hackishFieldName]

gives us the address of the field and so it can't change from managed code? Would it be right then to mark it as an invariant (it still can change due to GC, cant it?) and drop global?

@SingleAccretion
Copy link
Contributor

SingleAccretion commented Nov 5, 2021

gives us the address of the field and so it can't change from managed code?

Right. I guess technically it gives us "the base", we will also add an offset to it to get to the actual data, and that will be the value ldsflda gives us:

private static Vector128<int> _vtor;

[MethodImpl(MethodImplOptions.NoInlining)]
private static ref Vector128<int> AddressOfStructStatic()
{
    return ref _vtor;
}
N005 (  7, 15) [000004] ------------              *  RETURN    byref 
N004 (  6, 14) [000003] ------------              \--*  ADD       byref 
N002 (  4, 12) [000001] n-----------                 +--*  IND       ref   
N001 (  2, 10) [000000] I-----------                 |  \--*  CNS_INT(h) long   0xd1ffab1e static Fseq[_vtor]
N003 (  1,  1) [000002] ------------                 \--*  CNS_INT   long   8 Fseq[#FirstElem]

I don't think there is a combination of IL instructions that will allow one to get to the underlying box and mutate the reference itself.

Would it be right then to mark it as an invariant (it still can change due to GC, cant it?) and drop global?

I tried recently to mark it as invariant, but fgDebugCheckFlags was upset with me :), so I decided to look into it after some of my other work is finished. It is definitely "invariant" in the sense that it cannot be stored to, whether the VM can update it from under us I do not know. I guess I will say that we already model it as invariant when we don't expand it into its full form but instead use CLS_VAR, on 32 bit (and sometimes on 64 bit too):

static readonly Vector128<float> _vtor = Vector128.Create(1.0f, 2.0f, 3.0f, 4.0f);
static int _justSomeField;

private static Vector128<float> Vtors()
{
    var a = _vtor;

    _justSomeField = 1;

    for (int i = 0; i < 10; i++)
    {
        a = Sse.Add(a, _vtor);
    }

    return a;
}

- x86 codegen for the loop:

G_M54979_IG03:
       vaddps   xmm1, xmm1, xmm0
       inc      eax
       cmp      eax, 10
       jl       SHORT G_M54979_IG03

IR in VN:

***** BB02, STMT00004(before)
N008 ( 19, 16) [000025] -A-XG---R---              *  ASG       simd16 (copy)
N007 (  3,  2) [000023] D------N----              +--*  LCL_VAR   simd16<System.Runtime.Intrinsics.Vector128`1[Single]> V01 loc0         d:5
N006 ( 15, 13) [000022] ---XG-------              \--*  HWINTRINSIC simd16 float Add
N001 (  3,  2) [000017] ------------                 +--*  LCL_VAR   simd16<System.Runtime.Intrinsics.Vector128`1[Single]> V01 loc0         u:4 (last use)
N005 ( 11, 10) [000021] ---XG-------                 \--*  OBJ       simd16<System.Runtime.Intrinsics.Vector128`1[Single]>
N004 (  5,  6) [000020] ----G-------                    \--*  ADD       byref 
N002 (  3,  4) [000018] ----G-------                       +--*  CLS_VAR   ref    Hnd=0xd1ffab1e Fseq[_vtor]
N003 (  1,  1) [000019] ------------                       \--*  CNS_INT   int    4 Fseq[#FirstElem]

N001 [000017]   LCL_VAR   V01 loc0         u:4 (last use) => $2c0 {PhiDef($1, $4, $1c3)}
    FieldSeq {_vtor} is $180
N002 [000018]   CLS_VAR   Hnd=0xd1ffab1e Fseq[_vtor] => $81 {PtrToStatic($180)}
N003 [000019]   CNS_INT   4 Fseq[#FirstElem] => $42 {IntCns 4}
    FieldSeq {#FirstElem} is $181
  fieldSeq $182 is  {(_vtor, #FirstElem)}
N004 [000020]   ADD       => $82 {PtrToStatic($182)}
  Known type Vector128<float>
  VNApplySelectors:
    VNForHandle(_vtor) is $140, fieldType is simd16, size = 16
      AX2: $140 != $142 ==> select([$240]store($100, $142, $43), $140) ==> select($100, $140) remaining budget is 99.
    VNForMapSelect($240, $140):simd16 returns $1c0 {$100[$140]}
N005 [000021]   OBJ       => <l:$1c2 {norm=$1c0 {$100[$140]}, exc=$183 {NullPtrExc($82)}}, c:$1c4 {norm=$202 {MemOpaque:L00}, exc=$183 {NullPtrExc($82)}}>
N006 [000022]   HWINTRINSIC => <l:$1c8 {norm=$1c6 {HWI_SSE_Add($2c0, $1c0)}, exc=$183 {NullPtrExc($82)}}, c:$1c7 {norm=$1c5 {HWI_SSE_Add($2c0, $202)}, exc=$183 {NullPtrExc($82)}}>
N007 [000023]   LCL_VAR   V01 loc0         d:5 => <l:$1c6 {HWI_SSE_Add($2c0, $1c0)}, c:$1c5 {HWI_SSE_Add($2c0, $202)}>
N008 [000025]   ASG       => <l:$1c8 {norm=$1c6 {HWI_SSE_Add($2c0, $1c0)}, exc=$183 {NullPtrExc($82)}}, c:$1c7 {norm=$1c5 {HWI_SSE_Add($2c0, $202)}, exc=$183 {NullPtrExc($82)}}>

(We label it as PtrToStatic in its CLS_VAR form, we don't do it in the full expanded form because we think it is an actual struct field, but the two forms are equivalent semantically)

@sandreenko
Copy link
Contributor Author

Very interesting,

whether the VM can update it from under us I do not know.

the only scenario that I can imagine is GC.collect but then its VM responsibility to update the result of the IND.

I tried recently to mark it as invariant, but fgDebugCheckFlags was upset with me :)

we can try to combine these fixes for fgDebugCheckFlags with your work, could you share the diffs so I can try to play with them?

@AndyAyersMS
Copy link
Member

It would be nice to separate out refactorings/cleanups (like wider use of GenTreeFlags) from behavior changes. So maybe just do a refactor PR first?

As others have noted, access to some statics might require more than one indir; I believe all save the outermost should be invariant and non-faulting.

@sandreenko
Copy link
Contributor Author

It would be nice to separate out refactorings/cleanups (like wider use of GenTreeFlags) from behavior changes. So maybe just do a refactor PR first?

sure, the refactorings came last moment when I was analyzing regressions and was surprised that the flags are not shown under the debugger, I will extract this change.

@SingleAccretion
Copy link
Contributor

could you share the diffs so I can try to play with them?

I did not do much - just marked the address indirection as invariant. The problem was that the handle under it implies a mutable static, so that's why the checker was complaining. I then (after the replays came back red) solved the problem that prompted to me to look into this in the first place in a different way.

@AndyAyersMS
Copy link
Member

@sandreenko is this ready for re-review?

@sandreenko sandreenko marked this pull request as draft November 12, 2021 01:46
@sandreenko
Copy link
Contributor Author

@sandreenko is this ready for re-review?

no, looks like we need to understand when to set GTF_IND_INVARIANT , when not to set GTF_GLOB_REF for these static fields in this PR otherwise it leads to regressions. And, looks like we don't have a good understanding of it now. I will play with it when I have time.

@ghost ghost closed this Dec 12, 2021
@ghost
Copy link

ghost commented Dec 12, 2021

Draft Pull Request was automatically closed for inactivity. Please let us know if you'd like to reopen it.

@ghost ghost locked as resolved and limited conversation to collaborators Jan 11, 2022
This pull request was closed.
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.

4 participants