KEMBAR78
JIT: Remove questionable transformation by EgorBo · Pull Request #95249 · dotnet/runtime · GitHub
Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Nov 26, 2023

No description provided.

@ghost ghost assigned EgorBo Nov 26, 2023
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 26, 2023
@ghost
Copy link

ghost commented Nov 26, 2023

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

Issue Details

null

Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented Nov 26, 2023

/azp run Fuzzlyn

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

Choose a reason for hiding this comment

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

What IR does this create for the example case we were looking at?

Copy link
Member Author

Choose a reason for hiding this comment

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

It used to be:

    [000002] ----G+-----                         *  CAST      long <- int
    [000001] n---G+-----                         \--*  IND       byte  
    [000000] H----+-----                            \--*  CNS_INT(h) long   0x7ffa2213f21a static Fseq[s_13]

to

    [000002] ----G+-----                         *  NOP       byte  
    [000001] n---G+-----                         \--*  IND       byte  
    [000000] H----+-----                            \--*  CNS_INT(h) long   0x7ffa2213f21a static Fseq[s_13]

Now it's:

    [000002] ----G+-----                         *  CAST      long <- int
    [000001] n---G+-----                         \--*  IND       byte  
    [000000] H----+-----                            \--*  CNS_INT(h) long   0x7ffa22c7f21a static Fseq[s_13]

to

    [000002] ----G+-----                         *  CAST      int <- byte <- int
    [000001] n---G+-----                         \--*  IND       byte  
    [000000] H----+-----                            \--*  CNS_INT(h) long   0x7ffa22c7f21a static Fseq[s_13]

Copy link
Member

Choose a reason for hiding this comment

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

That's still an illegal transformation in this case since the value was an argument. The new cast does not guarantee widening into the upper 32 bits like the original cast does.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jakobbotsch are you suggesting to remove the whole transformation?

Copy link
Member

Choose a reason for hiding this comment

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

It seems there are two separate questions:

  1. Who is invoking optNarrowTree in this way that changes semantics of the program? The transformation is questionable to me but it's because the end result is a change change in behavior -- and this PR still has that problem.
  2. Can we get rid of the weird passthrough GT_NOP? Yes, and this PR probably accomplishes that, but it seems a better way would be to refactor optNarrowTree to take a GenTree** so that it can just replace the use of the cast with the operand in this situation.

I'm more worried about (1) than (2), though it would also be nice to clean up (2).

@EgorBo EgorBo marked this pull request as ready for review November 27, 2023 10:07
@SingleAccretion
Copy link
Contributor

If you are deleting this quirky NOP variant, you can also delete code here:

if (tree->OperIs(GT_NOP))
{
// Pass through arg vn.
tree->gtVNPair = tree->AsOp()->gtOp1->gtVNPair;
}

and case GT_NOP (as well as adjust the comment) here:

case GT_NOP:
case GT_BOX:
case GT_ARR_ADDR:
// "optNarrowTree" sometimes inserts NOP nodes between defs and uses.
// In this case, remove the NOP. BOX/ARR_ADDR are such "passthrough"
// nodes by design, and at this point we no longer need them.
if (node->gtGetOp1() != nullptr)
{
use.ReplaceWith(node->gtGetOp1());
BlockRange().Remove(node);
node = node->gtGetOp1();
}
break;

@EgorBo
Copy link
Member Author

EgorBo commented Nov 28, 2023

/azp run Fuzzlyn

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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.

There's probably some more stuff to fix around optNarrowTree, but this looks good to me to unblock the Fuzzlyn runs.

gtEffectiveVal can be cleaned up too now if passthrough NOPs no longer exist... but doesn't necessarily have to be in this PR.

@EgorBo EgorBo merged commit 0a5e211 into dotnet:main Nov 28, 2023
@EgorBo EgorBo deleted the remove-questionable-transform branch November 28, 2023 18:47
@EgorBo EgorBo mentioned this pull request Nov 28, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 29, 2023
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

Successfully merging this pull request may close these issues.

JIT: Assertion failed '!"Unexpected small type in IR"'

3 participants