Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Jan 8, 2024

Closes #96612

@dotnet/jit-contrib It seems that in lower we have a worrisome pattern to handle nodes like this:

// Returns:
//     A pointer to the next node to evaluate. On no operation, returns nullptr.
//
GenTree* LowerFoo(GenTree* tree)
{
    if (!someValidation)
        return nullptr;

    return newNode->gtNext;
}

and then caller assumes that nullptr means nothing was handled. Which is not true - it could be handled and it's just that gtNext is nullptr.

This is exactly what happens with #96612
TryLowerAndOrToCCMP converts a binary op to GT_SECC and returns nullptr and then ContainBinaryNode fails because node is no longer a simple op.

The correct pattern should be

bool TryLowerFoo(GenTree* node, GenTree** next)
{
    if (!someValidation)
        return false;

    *next = newNode->gtNext;
    return true;
}

I'll inspect more functions for this pattern separately.

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

ghost commented Jan 8, 2024

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

Issue Details

@dotnet/jit-contrib It seems that in lower we have a worrisome pattern to handle nodes like this:

// Returns:
//     A pointer to the next node to evaluate. On no operation, returns nullptr.
//
GenTree* LowerFoo(GenTree* tree)
{
    if (someValidation)
        return nullptr;

    return newNode->gtNext;
}

and then caller assumes that nullptr means nothing was handled. Which is not true - it could be handled and it's just that gtNext is nullptr.

This is exactly what happens with #96612
TryLowerAndOrToCCMP converts a binary op to GT_SECC and returns nullptr and then ContainBinaryNode fails because node is no longer a simple op.

The correct pattern should be

bool TryLowerFoo(GenTree* node, GenTree** next)
...

I'll inspect more function for this pattern separately.

Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented Jan 8, 2024

/azp run runtime-coreclr pgo, runtime-coreclr libraries-pgo, runtime-coreclr pgostress

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Comment on lines 2447 to 2449
JITDUMP("Conversion was legal. Result:\n")
DISPTREERANGE(BlockRange(), tree)
JITDUMP("\n")
Copy link
Member

Choose a reason for hiding this comment

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

Why remove the semicolons? It looks odd to have statements without semicolons, even if the macro expansion allows it.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok will return it back, it's just that my Resharper++ highlights them as redundant which is annoying (will change its settings 🙂)

image

Copy link
Member

Choose a reason for hiding this comment

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

We should probably change the definition of JITDUMP to follow the coding conventions -- they call out to use do/while pattern, among other things to explicitly require semicolons at uses: https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/clr-jit-coding-conventions.md#1433-multi-statement-macro-functions

@EgorBo
Copy link
Member Author

EgorBo commented Jan 8, 2024

/azp run runtime-coreclr pgo, runtime-coreclr libraries-pgo, runtime-coreclr pgostress

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@EgorBo EgorBo merged commit 1df91d3 into dotnet:main Jan 8, 2024
@EgorBo EgorBo deleted the fix-pgo-bug branch January 8, 2024 16:30
@github-actions github-actions bot locked and limited conversation to collaborators Feb 8, 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

Successfully merging this pull request may close these issues.

Assertion failed 'OperIsSimple()' in pgo pipelines
2 participants