Skip to content

JIT: Optimize "X ^ 0" to "X" #65071

Closed
Closed

Description

@SkiFoD

Current implementation emits:

8B4510               mov      eax, dword ptr [rbp+10H]
83F000               xor      eax, 0

I suppose it can be simplified to

8B4510               mov      eax, dword ptr [rbp+10H]

https://godbolt.org/z/57fh1v6PK

I made a quick research and folded it in the lowering phase.
The diffs are quite small, but the folding may be useful.

before.txt
after.txt
diff_summary.6.md

@EgorBo, @SingleAccretion I would be happy to know your opinion if it is worth it to implement this optimization.

Activity

  1. ghost added
    area-CodeGen-coreclr
    on Feb 9, 2022
  2. ghost added
    untriaged
    on Feb 9, 2022
  3. added a commit that references this issue on Feb 9, 2022
  4. EgorBo commented on Feb 9, 2022

    @EgorBo
    Member

    @EgorBo, @SingleAccretion I would be happy to know your opinion if it is worth it to implement this optimization.

    why not if it produces diffs 🙂

    Have you measured the diffs if it's done in morph instead? I guess it should be a pretty straightforward change in morph.
    E.g. I believe we already have x * 0 there

  5. SkiFoD commented on Feb 9, 2022

    @SkiFoD
    ContributorAuthor

    @EgorBo, @SingleAccretion I would be

    happy to know your opinion if it is worth it to implement this optimization.

    why not if it produces diffs 🙂

    Have you measured the diffs if it's done in morph instead? I guess it should be a pretty straightforward change in morph. E.g. I believe we already have x * 0 there

    I tried to implement it in morph at first, it produced these regressions (diff_summary.3.md)

    However, I think it could happen because I missed something.

  6. SkiFoD commented on Feb 9, 2022

    @SkiFoD
    ContributorAuthor

    I moved the optimization to morph phase.
    Here are asmdiffs for x64
    diff_summary.10.md
    I couldn't get rid of the regressions. There are 190 of them, which doesn't feel right to me.

  7. removed
    untriaged
    on Feb 11, 2022
  8. added this to the 7.0.0 milestone on Feb 11, 2022
  9. JulieLeeMSFT commented on Jun 10, 2022

    @JulieLeeMSFT
    Member

    @SkiFoD, the code complete for .NET 7 is July 11th. Do you think you can complete this before that? If not, we can move this to .NET 8.

  10. tannergooding commented on Jun 11, 2022

    @tannergooding
    Member

    I couldn't get rid of the regressions. There are 190 of them, which doesn't feel right to me

    Examples of the regressions would be beneficial (that is the actual assembly before/after). Often times regressions may simply be the JIT being able to kick in additional optimizations once the IR has simplified.

  11. SkiFoD commented on Jun 11, 2022

    @SkiFoD
    ContributorAuthor

    @JulieLeeMSFT @tannergooding Hey everyone. The code has been already merged here #65072

  12. ghost locked as resolved and limited conversation to collaborators on Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions