You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additions
ECMA-335 specifies the no. opcode prefix as the following (III.2.2):
This prefix indicates that the subsequent instruction need not perform the specified fault check
when it is executed. The byte that follows the instruction code indicates which checks can
optionally be skipped.
In short, it allows for automatic type checks, range checks or null checks to be skipped, which would be useful for optimizing hot code paths.
The current implementation throws InvalidProgramException whenever it encounters this prefix. This opcode is simply marked as unused right now:
Reacted by Dominique Schuppli, Julius R Friedman, Jacek Blaszczynski, John Kelly, Levi Broderick, Sergio Pedri, Abel Braaksma, Patrick Meinecke and IS4
I would think that, at the very least, we should ignore the opcode (other than the "correctness/verifiability" checks) rather than throwing InvalidProgramException.
This prefix indicates that the subsequent instruction need not perform the specified fault check
when it is executed. The byte that follows the instruction code indicates which checks can
optionally be skipped. This instruction is not verifiable.
0x01: typecheck (castclass, unbox, ldelema, stelem, stelem). The CLI can optionally skip
any type checks normally performed as part of the execution of the subsequent instruction.
InvalidCastException can optionally still be thrown if the check would fail.
0x02: rangecheck (ldelem., ldelema, stelem.). The CLI can optionally skip any array range
checks normally performed as part of the execution of the subsequent instruction.
IndexOutOfRangeException can optionally still be thrown if the check would fail.
0x04: nullcheck (ldfld, stfld, callvirt, ldvirtftn, ldelem., stelem., ldelema). The CLI can
optionally skip any null-reference checks normally performed as part of the execution of the
subsequent instruction. NullReferenceException can optionally still be thrown if the check
would fail.
I would think that, at the very least, we should ignore the opcode (other than the "correctness/verifiability" checks) rather than throwing InvalidProgramException.
This would also be a completely valid implementation of the instructions. Unlike the tail. prefix, the no. prefix specifies optional behavior.
Yes, it's optional, and ignoring it would be the very least in order to satisfy the spec.
But I'd like to see it fully supported. I'm not familiar with the JIT implementation so I'm speculating here, but I'd guess that optionally removing existing checks shouldn't be too hard to implement.
If there is still use in this, I am currently implementing this so that the JIT just ignores it - during import, it just validates that the flags are correct and the opcode is correct and then does nothing with it. However, there are a couple of questions around it i am not sure about:
Should no. 0x00 be invalid, or the same as not having it? (currently illegal to not have it
Should we just read the bits of interest (0x1, 0x2, 0x4), or should we ensure no other bits are set?
Should there be a PREFIX_NO added to prefixFlags that is set, but just currently ignored, or should it not do that and have no side effects other than necessary (codeAddr++ etc)?
Implementing it so it is ignored would mean there was the potential for langs to expose it, even if it initially does nothing, which could make it worth it to actually make it omit the checks
If future compatibility is what you want, I'd just ignore all invalid uses. This could be helpful if another flag is added to the instruction in the future. But that's only my opinion 😉
Currently have set it to only read bits it should be concerned with, so yeah, invalid and zero values are allowed. Am currently attempting to implement removal of range checks through GTF_INX_RNGHCK, so that will give it some actual meaning.
However, small issue so far :| no. prefix is basically 3 seperate prefixes - typecheck, rangecheck, nullcheck, and they are all fundamentally different. I need to represent them in prefixFlags, which is across the board stored as int, pictured here:
The last 4 are added by me. Annoyingly, the third one, NULLCHK, overflows int data type, so either I need to drop support for one of the options or the enum needs to be promoted to __int64 or similar. This is my first time doing any contribution to the JIT so I have no clue whether that is ok or who to ask if it is, so any advice appreciated
Why is this written in hex in the first place? There must be a good reason as 0x100 is not the same as 1 << 2 and wastes space: you'd get room for 32 bits if you use 1 << 0, 1 << 1, 1 << 2 and so on...
I am appalled i did not notice a) it was in hex and b) if that was binary there would be values left over. Thanks for the help, but sorry for the appallingly stupid question 😂
Draft PR up at dotnet/coreclr#23851, has a couple of typos with variable names and there might be an erroneous bracket (fixed on local, will push when I next can), but that's not an issue atm because the code is never reached due to this weird disappearance of the prefix
Is this on the roadmap? I've done awful things to trick the JIT into emitting the equivalent of a .no rangecheck|nullcheck ldelema in a project I maintain which I'd love to get rid of when compiling for netcoreapp3(.1?)+ targets.
This got lost, but I came back to it today and have a working version that supports and verifies all combinations of no. prefix. It has no tests tho, because I have no clue where/how to write JIT tests (that also need to be written in IL because it is not emitted by roslyn). It is spec compliant, as it is just a hint, but right now it has no actual functionality (it is verified and immediately discarded).
(From ECMA)
The byte that follows the instruction code indicates which checks can optionally be skipped.
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additions
Activity
tannergooding commentedon Apr 9, 2018
I would think that, at the very least, we should ignore the opcode (other than the "correctness/verifiability" checks) rather than throwing
InvalidProgramException.I do think that supporting the opcode would be beneficial though, as it is basically a built-in way of doing certain JIT hints (https://github.com/dotnet/corefx/issues/26188).
tannergooding commentedon Apr 9, 2018
NOTE: Ignoring the prefix is allowed by the spec:
sharwell commentedon Apr 9, 2018
This would also be a completely valid implementation of the instructions. Unlike the
tail.prefix, theno.prefix specifies optional behavior.ltrzesniewski commentedon Apr 9, 2018
Yes, it's optional, and ignoring it would be the very least in order to satisfy the spec.
But I'd like to see it fully supported. I'm not familiar with the JIT implementation so I'm speculating here, but I'd guess that optionally removing existing checks shouldn't be too hard to implement.
Add support for IL `no.` instruction prefix
john-h-k commentedon Apr 8, 2019
If there is still use in this, I am currently implementing this so that the JIT just ignores it - during import, it just validates that the flags are correct and the opcode is correct and then does nothing with it. However, there are a couple of questions around it i am not sure about:
no. 0x00be invalid, or the same as not having it? (currently illegal to not have itPREFIX_NOadded toprefixFlagsthat is set, but just currently ignored, or should it not do that and have no side effects other than necessary (codeAddr++ etc)?ltrzesniewski commentedon Apr 8, 2019
TBH implementing it so it's ignored is wasted effort unless it's a first step towards real support.
john-h-k commentedon Apr 8, 2019
Implementing it so it is ignored would mean there was the potential for langs to expose it, even if it initially does nothing, which could make it worth it to actually make it omit the checks
john-h-k commentedon Apr 8, 2019
Also, to be picky, helps ECMA compliance
ltrzesniewski commentedon Apr 8, 2019
If future compatibility is what you want, I'd just ignore all invalid uses. This could be helpful if another flag is added to the instruction in the future. But that's only my opinion 😉
john-h-k commentedon Apr 8, 2019
Currently have set it to only read bits it should be concerned with, so yeah, invalid and zero values are allowed. Am currently attempting to implement removal of range checks through
GTF_INX_RNGHCK, so that will give it some actual meaning.john-h-k commentedon Apr 8, 2019
However, small issue so far :|

no.prefix is basically 3 seperate prefixes -typecheck, rangecheck, nullcheck, and they are all fundamentally different. I need to represent them inprefixFlags, which is across the board stored asint, pictured here:The last 4 are added by me. Annoyingly, the third one, NULLCHK, overflows
intdata type, so either I need to drop support for one of the options or the enum needs to be promoted to__int64or similar. This is my first time doing any contribution to the JIT so I have no clue whether that is ok or who to ask if it is, so any advice appreciatedAndyAyersMS commentedon Apr 8, 2019
We should be able to represent 32 flags in an int, not 8. Can't you use a 0x2, 0x4, or 0x8 based value?
ltrzesniewski commentedon Apr 8, 2019
Why is this written in hex in the first place? There must be a good reason as
0x100is not the same as1 << 2and wastes space: you'd get room for 32 bits if you use1 << 0,1 << 1,1 << 2and so on...john-h-k commentedon Apr 8, 2019
I am appalled i did not notice a) it was in hex and b) if that was binary there would be values left over. Thanks for the help, but sorry for the appallingly stupid question 😂
21 remaining items
john-h-k commentedon Apr 10, 2019
Draft PR up at dotnet/coreclr#23851, has a couple of typos with variable names and there might be an erroneous bracket (fixed on local, will push when I next can), but that's not an issue atm because the code is never reached due to this weird disappearance of the prefix
john-h-k commentedon Apr 10, 2019
@AndyAyersMS I used Product
AndyAyersMS commentedon Apr 10, 2019
I'll take a look when I get a chance, might be a day or two.
Add support for IL `no.` instruction prefix
WIP - omit rangechecks for no. prefixes
phdjonov commentedon Jul 15, 2019
Is this on the roadmap? I've done awful things to trick the JIT into emitting the equivalent of a
.no rangecheck|nullcheck ldelemain a project I maintain which I'd love to get rid of when compiling for netcoreapp3(.1?)+ targets.Add support for IL `no.` instruction prefix
WIP - omit rangechecks for no. prefixes
john-h-k commentedon Apr 26, 2020
This got lost, but I came back to it today and have a working version that supports and verifies all combinations of
no.prefix. It has no tests tho, because I have no clue where/how to write JIT tests (that also need to be written in IL because it is not emitted by roslyn). It is spec compliant, as it is just a hint, but right now it has no actual functionality (it is verified and immediately discarded).(From ECMA)
am11 commentedon Apr 26, 2020
See https://github.com/dotnet/runtime/blob/b93693ed830a944dde64138d305e3506bcaea911/src/coreclr/tests/src/JIT/IL_Conformance/Old/Conformance_Base/
Not sure if
Oldin its path means obsolete, but ckfinite ILOpcode is also not emitted by roslyn and tested directly via IL.john-h-k commentedon Apr 26, 2020
Awesome, I'll start on that. In the meantime, worth opening a draft PR to show the diff?