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 latest base register while accessing the stack #38834

Merged
merged 16 commits into from
Jul 8, 2020

Conversation

kunalspathak
Copy link
Member

@kunalspathak kunalspathak commented Jul 6, 2020

When we try to access a field of a struct parameter, we calculate the offset of field using wrong base register. The struct that is getting accessed has 257 fields and we use sp as a base register to calculate the offset. However at 152nd field we reach the encoding limit of 0xFF8 and hence decide to use fp as a new base register to calculate the offset from. But we don't take the new base register into account when calculating the final indirect of the field.

Here is the snippet of code that loads each field .

    
    movw    r10, 0xfe8
    add     r10, sp
    vldr    d10, [r10]  ; field access
    movw    r10, 0xff0
    add     r10, sp
    vldr    d10, [r10]  ; field access
 
    movw    r10, 0xff8
    add     r10, sp
    vldr    d10, [r10]   ; field access
 
    movw    r10, 0x4c0
    add     r10, sp     ; <-- this should be "add     r10, r11"
    vldr    d10, [r10]
 
    movw    r10, 0x4c8
    add     r10, sp
    vldr    d10, [r10]

The fix is to use the latest base register we find out (through lvaFrameAddress) inside emitIns_R_S() when called with INS_movw and propagate it via emitIns_genStackOffset(). In order to come up with a small repro case, I wanted to see how this situation arises with stress flags, but couldn't find exact reason. One thing that I noticed was in repro case, the compLclFrameSize is lot bigger than the non-repro case, but again was not sure enough.

I ran various jitstress pipelines and looks like the mcc_i* tests are passing. Here is the test log.

Fixes: #35501 and #36199

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 6, 2020
@kunalspathak kunalspathak marked this pull request as ready for review July 7, 2020 17:58
@kunalspathak kunalspathak changed the title Sp reg Use the latest base register while accessing the stack Jul 7, 2020
@kunalspathak
Copy link
Member Author

@dotnet/jit-contrib

Copy link
Contributor

@CarolEidt CarolEidt left a comment

Choose a reason for hiding this comment

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

The changes seem reasonable, but I would probably have used a return value for the base register (since these methods are currently void) rather than adding a pointer as an "out" parameter.

@kunalspathak
Copy link
Member Author

kunalspathak commented Jul 7, 2020

The changes seem reasonable, but I would probably have used a return value for the base register (since these methods are currently void) rather than adding a pointer as an "out" parameter.

Thanks @CarolEidt . My first thought was to return a value but since it was one of the emitIns_* methods which has return signature as void, I do not wanted to break the consistency. If it is ok with you, I will change it to return instead of out parameter.

@CarolEidt
Copy link
Contributor

If it is ok with you, I will change it to return instead of out parameter.

To me, the inconsistency actually makes it clearer that these methods are "special", though I supposed there's also the danger that the caller will ignore the return value, since C++ makes it easy to do so. Do others have different opinions? @dotnet/jit-contrib

@echesakov
Copy link
Contributor

Do others have different opinions? @dotnet/jit-contrib

I would just go with return type = void and returning the base register via out parameter (that should be named pBaseReg)

Copy link
Contributor

@CarolEidt CarolEidt left a comment

Choose a reason for hiding this comment

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

LGTM

@CarolEidt
Copy link
Contributor

added standard function header

Thanks!

@kunalspathak kunalspathak merged commit 8988325 into dotnet:master Jul 8, 2020
@kunalspathak kunalspathak deleted the sp_reg branch July 8, 2020 06:34
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
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.

Test failure: JIT\\jit64\\mcc\\interop\\mcc_i77\\mcc_i77.cmd
4 participants