In IL code, why is there not a nop opcode in a given situation? Why is there a br.s opcode in a given situation?

不羁岁月 提交于 2019-12-04 05:07:57
Hans Passant

The C# compiler emits a NOP instruction at a curly brace. Which makes it a lot easier to set breakpoints in your code. The debugger only permits setting a breakpoint on code and a curly brace doesn't normally produce any code. So this is just a simple debugging aid, these NOPs won't get generated in the release build.

The BR.S instruction is a minor flaw in the compiler, it doesn't have a peephole optimizer to get rid of these kind of extraneous instructions. In general, it is not the job of the C# compiler to optimize code, that's done by the jitter. Which will readily and easily remove the instruction.

All of what you see is because you're compiling in Debug mode. The redundant jumps and nops are disabled optimization passes as well as debugging support (I believe).

Compile in Release mode.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!