-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JIT: Ensure last-use copy omission candidates are marked with GTF_GLO…
…B_REF (#89088) Last-use copy omission allows the JIT to avoid creating copies of struct values that are passed implicitly by-ref when the value is a last-use of a local. When we do this we effectively address expose the local for the lifetime of the call, so we mark the local as address exposed as part of doing so. However, there is a problem where morph may reorder two uses of a such a local and break the last use information. For example, consider the following case: ``` [000015] --CXG------ ▌ CALL void Program:Foo(int,int) [000010] ----------- arg0 ├──▌ LCL_FLD int V00 loc0 [+0] [000012] --CXG------ arg1 └──▌ CALL int Program:Bar(S):int [000011] ----------- arg0 └──▌ LCL_VAR struct<S, 32> V00 loc0 (last use) ``` V00 is used both at [000010] and at [000011], the latter as a last use. Since we only address expose V00 when we get to [000011] we do not mark [000010] with GTF_GLOB_REF; the net effect is the following call args morphing, where we have reordered the two occurrences illegally: ``` [000015] --CXG+----- ▌ CALL void Program:Foo(int,int) [000037] DACXG------ arg1 setup ├──▌ STORE_LCL_VAR int V04 tmp3 [000012] --CXG+----- │ └──▌ CALL int Program:Bar(S):int [000011] -----+----- arg0 in rcx │ └──▌ LCL_ADDR long V00 loc0 [+0] [000038] ----------- arg1 in rdx ├──▌ LCL_VAR int V04 tmp3 [000010] -----+----- arg0 in rcx └──▌ LCL_FLD int (AX) V00 loc0 [+0] ``` This change fixes the problem by running a separate pass over the IR before morph to identify and address expose the candidates for last-use copy omission. The net result is then the following correct IR: ``` [000015] --CXG+----- ▌ CALL void Runtime_85611:Foo(int,int) [000039] DA--G------ arg0 setup ├──▌ STORE_LCL_VAR int V05 tmp4 [000010] ----G+----- │ └──▌ LCL_FLD int (AX) V00 loc0 [+0] [000037] DACXG------ arg1 setup ├──▌ STORE_LCL_VAR int V04 tmp3 [000012] --CXG+----- │ └──▌ CALL int Runtime_85611:Bar(Runtime_85611+S):int [000011] ----G+----- arg0 in rcx │ └──▌ LCL_ADDR long V00 loc0 [+0] [000038] ----------- arg1 in rdx ├──▌ LCL_VAR int V04 tmp3 [000040] ----------- arg0 in rcx └──▌ LCL_VAR int V05 tmp4 ``` The pass has some TP impact but it is mitigated since we only need to visit statements with GTF_CALL and since we can use the locals tree list to prune which statements we visit. Fix #85611
- Loading branch information
1 parent
d051a84
commit 3b46cf5
Showing
6 changed files
with
257 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.