inplace increment operator causes register spilling (.NET 7) #93733
Answered
by
tannergooding
lakecherry
asked this question in
Q&A
-
expected x64:
reality x64:
separating increment and compare gets expected code:
same for int ... any recommendations? (the oneliner version would of course be much more coding-friendly) |
Beta Was this translation helpful? Give feedback.
Answered by
tannergooding
Oct 20, 2023
Replies: 1 comment 3 replies
-
Increment inside a condition is slightly dangerous, in that it can cause confusion for less experienced coders (especially if they try to "fix" it to be a postfix increment, here). |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The post-increment and pre-increment operators are likewise not exactly "basic", even if they appear to be.
In IL,
someInt32++
is represented as:Where-as
someByte++
is represented as:This is because there doesn't exist a stack type for
byte
, theldarg.1
implicitly upcasts it to ani4
.The reason there isn't a stack type for
byte
orshort
is largely because such operations are generally not as optimizable or efficient at the hardware level. CPUs largely operate on32-bit
or64-bit
registers. They sometimes provide access to 8 or 16-bit subsections of those registers, but accessing them often involves (internally) a s…