Why are compilers so stupid?

前端 未结 29 1936
借酒劲吻你
借酒劲吻你 2020-11-29 18:07

I always wonder why compilers can\'t figure out simple things that are obvious to the human eye. They do lots of simple optimizations, but never something even a little bit

29条回答
  •  离开以前
    2020-11-29 18:58

    Because compiler writers try add optimizations for things that matter (I hope) and that are measured in *Stone benchmarks (I fear).

    There are zillions of other possible code fragments like yours, which do nothing and could be optimized with increasing effort on the compiler writer, but which are hardly ever encountered.

    What I feel embarrassing is that even today most compilers generate code to check for the switchValue being greater than 255 for a dense or almost full switch on an unsigned character. That adds 2 instructions to most bytecode interpreter's inner loop.

提交回复
热议问题