Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the register of CAST for contained index operator #74275

Merged
merged 12 commits into from
Sep 5, 2022

Conversation

kunalspathak
Copy link
Member

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 19, 2022
@ghost ghost assigned kunalspathak Aug 19, 2022
@ghost
Copy link

ghost commented Aug 19, 2022

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
Member Author

@dotnet/jit-contrib

Comment on lines +4417 to +4474
else if (index->OperIs(GT_CAST))
{
index = index->AsCast()->gtGetOp1();
}
Copy link
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
Member Author

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
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
Member

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

@kunalspathak
Copy link
Member Author

@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.

@JulieLeeMSFT JulieLeeMSFT added this to the 7.0.0 milestone Aug 22, 2022
Copy link
Contributor

@SingleAccretion SingleAccretion left a comment

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)]
private static void Problem(ref byte x, int a)
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    static byte GetByte() => 1;

    JitUse(&a);
    Unsafe.Add(ref x, a) = GetByte();
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void JitUse<T>(T* arg) where T : unmanaged { }

@kunalspathak
Copy link
Member Author

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

@kunalspathak
Copy link
Member Author

@EgorBo - can you take a look?

src/coreclr/jit/codegenarmarch.cpp Outdated Show resolved Hide resolved
@EgorBo
Copy link
Member

EgorBo commented Sep 5, 2022

@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:main Sep 5, 2022
@kunalspathak kunalspathak deleted the index_contained branch September 5, 2022 17:08
@kunalspathak
Copy link
Member Author

/backport to release/7.0-rc1

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2022

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

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2022

@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 for src/tests/JIT/Regression/JitBlue/Runtime_74373/Runtime_73821.cs, which is not in 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
Member Author

/backport to release/7.0

@github-actions
Copy link
Contributor

github-actions bot commented Sep 6, 2022

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

@github-actions
Copy link
Contributor

github-actions bot commented Sep 6, 2022

@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
@ghost ghost locked as resolved and limited conversation to collaborators Oct 6, 2022
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 'isGeneralRegister(reg3)'
5 participants