Skip to content

Use the register of CAST for contained index operator - #74275

Merged
kunalspathak merged 12 commits into
dotnet:mainfrom
kunalspathak:index_contained
Sep 5, 2022
Merged

Use the register of CAST for contained index operator#74275
kunalspathak merged 12 commits into
dotnet:mainfrom
kunalspathak:index_contained

Conversation

@kunalspathak

Copy link
Copy Markdown
Contributor

If index is contained and the underlying operator is GT_CAST we were not handling that case and that led to using REG_COUNT register from index in genScaledAdd() . I have fixed it and also added checks to see if more such cases are missing.

Fixes: #74117

@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 19, 2022
@ghost

Copy link
Copy Markdown

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

Issue Details

If index is contained and the underlying operator is GT_CAST we were not handling that case and that led to using REG_COUNT register from index in genScaledAdd() . I have fixed it and also added checks to see if more such cases are missing.

Fixes: #74117

Author:kunalspathak
Assignees:-
Labels:

area-CodeGen-coreclr

Milestone:-

@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

@dotnet/jit-contrib

Comment threadsrc/coreclr/jit/codegenarmarch.cpp Outdated
Comment on lines 4417 to 4474

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What kind of cast gets here? CAST<long>(int)? But then what is doing the sign/zero-extension?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

N006 ( 4, 6) [000018] -c--G----U- t18 = * CAST long <- uint $1c0
/--* t19 byref +--* t18 long N007 ( 6, 8) [000020] ----------- t20 = * LEA(b+(i*1)+0) byref 

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, so it is indeed CAST<long>(int). There is still the question of what is doing the extension (is it perhaps unnecessary)?

@JulieLeeMSFT

Copy link
Copy Markdown
Member

@kunalspathak, @dotnet/jit-contrib, are we going to backport it to 7?

@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

@kunalspathak, @dotnet/jit-contrib, are we going to backport it to 7?

Probably. This issue is around the code that was introduced in .NET 7.

@JulieLeeMSFTJulieLeeMSFT added this to the 7.0.0 milestone Aug 22, 2022
Comment threadsrc/coreclr/jit/lower.cpp Outdated
Comment threadsrc/coreclr/jit/lower.cpp Outdated

@SingleAccretionSingleAccretion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code changes LGTM. We may find out the upfront IsSafeToContainMem it too expensive TP-wise and will need to move it down after the other checks, but hopefully not.

I've also filed #74448 to track the complete fix, you could add a link to it from codegen (or not).

Also it would be nice to add a regression test, say:

[MethodImpl(MethodImplOptions.NoInlining)]privatestaticvoidProblem(refbytex,inta){[MethodImpl(MethodImplOptions.NoInlining)]staticbyteGetByte()=>1;JitUse(&a);Unsafe.Add(refx,a)= GetByte();}[MethodImpl(MethodImplOptions.NoInlining)]publicstaticvoidJitUse<T>(T*arg)whereT: unmanaged {}

Comment threadsrc/coreclr/jit/lower.cpp Outdated
@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

@dotnet/jit-contrib - can someone review it?

@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

@EgorBo - can you take a look?

Comment threadsrc/coreclr/jit/codegenarmarch.cpp Outdated
@EgorBo

EgorBo commented Sep 5, 2022

Copy link
Copy Markdown
Member

@EgorBo - can you take a look?

oops, sorry for the delay - didn't notice this mention, something is wrong with my mail filters. LGTM btw

@kunalspathak
kunalspathak merged commit fd11209 into dotnet:mainSep 5, 2022
@kunalspathak
kunalspathak deleted the index_contained branch September 5, 2022 17:08
@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

/backport to release/7.0-rc1

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/7.0-rc1: https://github.com/dotnet/runtime/actions/runs/2995029976

@github-actions

Copy link
Copy Markdown
Contributor

@kunalspathak backporting to release/7.0-rc1 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Rename test files
error: mode change forsrc/tests/JIT/Regression/JitBlue/Runtime_74373/Runtime_73821.cs, which is notin current HEAD
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Rename test files
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

/backport to release/7.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3002058907

@github-actions

Copy link
Copy Markdown
Contributor

@kunalspathak backporting to release/7.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Rename test files
Applying: Fix index scale for cast
Applying: Do not contain index if indir is not containable.
Applying: Revert "Do not contain index if indir is not containable."
Applying: Instead try to contain the LEA
Using index info to reconstruct a base tree...
M	src/coreclr/jit/lower.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/jit/lower.cpp
CONFLICT (content): Merge conflict in src/coreclr/jit/lower.cpp
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0005 Instead try to contain the LEA
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

kunalspathak added a commit to kunalspathak/runtime that referenced this pull request Sep 6, 2022
* Rename test files
* Fix index scale for cast
* Do not contain index if indir is not containable.
* Revert "Do not contain index if indir is not containable."
This reverts commit e79d17d92ceb0eed5ae1bfd03c2d1d6b171ab17f.
* Instead try to contain the LEA
* IsSafeToContainMem() check
* Do IsSafeToContainMem() only if needed
* Add test case
* Fix merge error
* fix the test case
* review comment
carlossanlop pushed a commit that referenced this pull request Sep 7, 2022
* Rename test files
* Fix index scale for cast
* Do not contain index if indir is not containable.
* Revert "Do not contain index if indir is not containable."
This reverts commit e79d17d92ceb0eed5ae1bfd03c2d1d6b171ab17f.
* Instead try to contain the LEA
* IsSafeToContainMem() check
* Do IsSafeToContainMem() only if needed
* Add test case
* Fix merge error
* fix the test case
* review comment
@ghostghost locked as resolved and limited conversation to collaborators Oct 6, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclrCLR 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 'isGeneralRegister(reg3)'

5 participants

@kunalspathak@JulieLeeMSFT@EgorBo@BruceForstall@SingleAccretion