Skip to content

[Question] impCloneExpr vs fgInsertCommaFormTemp + gtCloneExpr #35314

Closed

Description

@tannergooding

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

Activity

  1. added
    area-CodeGen-coreclr
    untriaged
    on Apr 22, 2020
  2. tannergooding commented on Apr 22, 2020

    @tannergooding
    MemberAuthor

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

  3. CarolEidt commented on Apr 23, 2020

    @CarolEidt
    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?

  4. tannergooding commented on Apr 23, 2020

    @tannergooding
    MemberAuthor

    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.

  5. EgorBo commented on Apr 23, 2020

    @EgorBo
    Member

    in my PR I used

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

    (not sure OperIsLeaf() is necessary)

  6. AndyAyersMS commented on Apr 23, 2020

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

  7. added this to the 5.0 milestone on Apr 24, 2020
  8. removed
    untriaged
    on Apr 24, 2020
  9. AndyAyersMS commented on Jul 1, 2020

    @AndyAyersMS
    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?

  10. tannergooding commented on Jul 1, 2020

    @tannergooding
    MemberAuthor

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

  11. AndyAyersMS commented on Jul 1, 2020

    @AndyAyersMS
    Member

    Ok, I'm going to move this.

  12. modified the milestones: 5.0.0, Future on Jul 1, 2020
  13. added
    JitUntriaged
    on Oct 28, 2020
  14. removed
    JitUntriaged
    on Jan 24, 2023
  15. locked and limited conversation to collaborators on Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclr

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions