Skip to content

Conversation

@kunalspathak
Copy link
Contributor

Pass the correct size of instruction to determine if the immediate will fit in the instruction or not.

Fixes: #68536

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Sep 7, 2023
@ghost ghost assigned kunalspathak Sep 7, 2023
@ghost
Copy link

ghost commented Sep 7, 2023

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

Issue Details

Pass the correct size of instruction to determine if the immediate will fit in the instruction or not.

Fixes: #68536

Author: kunalspathak
Assignees: kunalspathak
Labels:

area-CodeGen-coreclr

Milestone: -

@kunalspathak kunalspathak marked this pull request as ready for review September 8, 2023 13:56
@kunalspathak
Copy link
Contributor Author

@dotnet/jit-contrib

case INS_ldrsh:
case INS_ldrsw:
case INS_ldrb:
immFitsInIns = emitter::emitIns_valid_imm_for_ldst_offset(imm, EA_1BYTE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is size not already EA_1BYTE in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is passed by the caller genEnregisterOSRArgsAndLocals() using emitActualTypeSize(lclTyp), which for TYP_BYTE returns EA_4BYTE.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like the bug is in genEnregisterOSRArgsAndLocals() -- it appears lclTyp is TYP_BYTE so it is asking for a ldrb but it passes the actual size (4) instead of size 1. It looks like lclTyp can only be small for OSR local struct fields. Maybe it should use const emitAttr size = emitTypeSize(lclTyp); instead of using emitActualTypeSize()? @AndyAyersMS ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think we should be using emitTypeSize in genEnregisterOSRArgsAndLocals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like lclTyp can only be small for OSR local struct fields.

Why is the reasoning behind it?

emitTypeSize

I never understood the difference between emitTypeSize and emitActualTypeSize(). In which scenarios should we use one over other?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out that for emit_R_R_I() format, if we are sign extending, we expect the size to be valid general size i.e. 4 bytes or 8 bytes, so changing to emitTypeSize() hits an assert. I will follow up offline with @BruceForstall .

@kunalspathak
Copy link
Contributor Author

@BruceForstall PTAL.

@kunalspathak kunalspathak merged commit 10f0277 into dotnet:main Sep 14, 2023
@kunalspathak kunalspathak deleted the LS_2B branch September 14, 2023 03:34
@kunalspathak
Copy link
Contributor Author

/backport to release/8.0

@github-actions
Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6180624899

@ghost ghost locked as resolved and limited conversation to collaborators Oct 14, 2023
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 '!"Instruction cannot be encoded: IF_LS_2B"' during 'Generate code'

3 participants