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

[Question] impCloneExpr vs fgInsertCommaFormTemp + gtCloneExpr #35314

Closed
tannergooding opened this issue Apr 22, 2020 · 8 comments
Closed

[Question] impCloneExpr vs fgInsertCommaFormTemp + gtCloneExpr #35314

tannergooding opened this issue Apr 22, 2020 · 8 comments
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@tannergooding
Copy link
Member

tannergooding commented Apr 22, 2020

Looking at various parts of the importer, it looks like one of a couple approaches are used when a node needs to be copied. All of these code paths are functionally similar but with minor tweaks in the actual checks done and when a given node is copied to a local vs cloned. I was wondering if there is a "correct" one that should be getting used and if the various paths should be normalized to a single helper method?

The first is just calling impCloneExpr which calls gtClone if the tree isn't GTF_GLOB_EFFECT and is simple and which creates a new LCL_VAR node otherwise: https://github.com/dotnet/runtime/blob/master/src/coreclr/src/jit/importer.cpp#L2643

However, there are other areas that don't use this method and instead check for GTF_SIDE_EFFECT calling fgInsertCommaFormTemp and calling gtCloneExpr otherwise: https://github.com/dotnet/runtime/blob/master/src/coreclr/src/jit/simd.cpp#L1390-L1397

There are also some places that directly create an additional LCL_VAR node if it needs two copies of the data: https://github.com/dotnet/runtime/blob/master/src/coreclr/src/jit/simd.cpp#L1319

There are also various places that just directly clone or insert a temp without the above associated checks.

category:question
theme:importer
skill-level:intermediate
cost:medium

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI untriaged New issue has not been triaged by the area owner labels Apr 22, 2020
@tannergooding
Copy link
Member Author

CC. @CarolEidt since I saw these differences when going through simd.cpp

@CarolEidt
Copy link
Contributor

I suspect that these should be unified, though it wouldn't surprise me that some of the differences were due to some varying requirements based on what phase it's in.
@dotnet/jit-contrib - any other insights?

@tannergooding
Copy link
Member Author

I suspect that these should be unified, though it wouldn't surprise me that some of the differences were due to some varying requirements based on what phase it's in.

At least in the case of simd.cpp and hwintrinsic.cpp, it looks to all be during importation. Although, I didn't dig too deeply into all the callsites to validate that was definitely the case.

@EgorBo
Copy link
Member

EgorBo commented Apr 23, 2020

in my PR I used

auto cloned = gtCloneExpr(op1->OperIsLeaf() ? op1 : fgMakeMultiUse(&tree->AsOp()->gtOp1));

(not sure OperIsLeaf() is necessary)

@AndyAyersMS
Copy link
Member

impCloneExpr checks for interference of the tree against the IL stack. You need to call this in the importer unless you know for sure you can't have any such interference. It doesn't make sense to call impCloneExpr outside of importation.

@BruceForstall BruceForstall added this to the 5.0 milestone Apr 24, 2020
@BruceForstall BruceForstall removed the untriaged New issue has not been triaged by the area owner label Apr 24, 2020
@AndyAyersMS
Copy link
Member

Given that we haven't had any bugs (that I know of) from the variety of approaches to handling duplicated operands, I'm tempted to say we should put off any cleanup work until after 5.0. We can try to clean up/unify early in 6.0.

Thoughts?

@tannergooding
Copy link
Member Author

That sounds reasonable to me. I was mostly just interested as I had seen a number of varying mechanisms 😄

@AndyAyersMS
Copy link
Member

Ok, I'm going to move this.

@AndyAyersMS AndyAyersMS modified the milestones: 5.0.0, Future Jul 1, 2020
@BruceForstall BruceForstall added the JitUntriaged CLR JIT issues needing additional triage label Oct 28, 2020
@BruceForstall BruceForstall removed the JitUntriaged CLR JIT issues needing additional triage label Jan 24, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Mar 6, 2024
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
Projects
None yet
Development

No branches or pull requests

6 participants