Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented May 9, 2021

I noticed this pattern after loop clonning (it produces it for the condition for two loops), e.g.:

static void Test(int[] arr)
{
    int len = arr.Length;
    for (int i = 0; i < len; i++)
        arr[i] = 0;
}

Codegen diff: https://www.diffchecker.com/fdGIQqQJ

(Obviously, for this specific method the clonned loop should either be removed or not emitted in the first place but that is a different story)

SuperPMI diffs:

asm.aspnet.run.windows.x64.checked.1

Total bytes of base: 4071
Total bytes of diff: 3965
Total bytes of delta: -106 (-2.60% of base)
    diff is an improvement.
asm.benchmarks.run.windows.x64.checked.1

Total bytes of base: 34862
Total bytes of diff: 34379
Total bytes of delta: -483 (-1.39% of base)
    diff is an improvement.
asm.libraries.crossgen.windows.x64.checked.5

Total bytes of base: 64797
Total bytes of diff: 63798
Total bytes of delta: -999 (-1.54% of base)
    diff is an improvement.
asm.libraries.crossgen2.windows.x64.checked.3

Total bytes of base: 44678
Total bytes of diff: 43939
Total bytes of delta: -739 (-1.65% of base)
    diff is an improvement.
asm.libraries.pmi.windows.x64.checked.1

Total bytes of base: 75612
Total bytes of diff: 74511
Total bytes of delta: -1101 (-1.46% of base)
    diff is an improvement.
asm.tests.pmi.windows.x64.checked.1

Total bytes of base: 43352
Total bytes of diff: 42533
Total bytes of delta: -819 (-1.89% of base)
    diff is an improvement.
asm.tests_libraries.pmi.windows.x64.checked.1

Total bytes of base: 103704
Total bytes of diff: 102144
Total bytes of delta: -1560 (-1.50% of base)
    diff is an improvement.

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 9, 2021
@EgorBo
Copy link
Member Author

EgorBo commented May 10, 2021

@dotnet/jit-contrib @BruceForstall PTAL

Copy link
Contributor

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

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

LGTM.

@EgorBo EgorBo merged commit 130dc8d into dotnet:main May 10, 2021
}

// Fold "cmp & 1" to just "cmp"
if (tree->OperIs(GT_AND) && tree->TypeIs(TYP_INT) && op1->OperIsCompare() && op2->IsIntegralConst(1))
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, I am late for the review, two questions:

  1. do we want to do it when optimizations are disabled?
  2. Can op2 or tree be a CSE candidates that we destroy while CSE is keeping links on them?

Copy link
Member Author

@EgorBo EgorBo May 10, 2021

Choose a reason for hiding this comment

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

  1. I found plenty of such small peepholes in morph without OptimizationEnabled guard so it wasn't clear to me when we should really apply it - I guess we want to eventually have three different modes: MinOpts, tier0 (simple opts) and tier1 (all opts).

  2. op2 is always an integer const (1) and CSE doesn't work for them without a special switch -- so it's not a correct behavior to delete a potential CSE candidate and it might lead to a crash/assert?

Copy link
Contributor

Choose a reason for hiding this comment

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

op2 is always an integer const (1) and CSE doesn't work for them without a special switch -- so it's not a correct behavior to delete a potential CSE candidate and it might lead to a crash/assert?

the switch is on for arm64 but tree can be a CSE candidate without it. I would recommend adding a change to protect against it.

EgorBo added a commit to EgorBo/runtime-1 that referenced this pull request May 13, 2021
@EgorBo EgorBo mentioned this pull request May 13, 2021
ghost pushed a commit that referenced this pull request May 17, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jun 19, 2021
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.

4 participants