Skip to content

inplace increment operator causes register spilling (.NET 7) #93733

Answered by tannergooding
lakecherry asked this question in Q&A
Discussion options

You must be logged in to vote

The post-increment and pre-increment operators are likewise not exactly "basic", even if they appear to be.

In IL, someInt32++ is represented as:

ldarg.1
ldc.i4.1
add
starg.s x

Where-as someByte++ is represented as:

ldarg.1
ldc.i4.1
add
conv.u1
starg.s x

This is because there doesn't exist a stack type for byte, the ldarg.1 implicitly upcasts it to an i4.

The reason there isn't a stack type for byte or short is largely because such operations are generally not as optimizable or efficient at the hardware level. CPUs largely operate on 32-bit or 64-bit registers. They sometimes provide access to 8 or 16-bit subsections of those registers, but accessing them often involves (internally) a s…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@lakecherry
Comment options

@tannergooding
Comment options

Answer selected by lakecherry
@lakecherry
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants