2 comments

  • CalChris16 minutes ago
    Why is this known bits optimization being done by the JIT rather than the Java compiler?
    • cogman106 minutes ago
      Because you might want to put a breakpoint on that line of code and debug the variables going in and coming out.<p>But further, optimizing in the compiler can preclude future optimizations by the JIT. Giving the JIT more information can make it make better decisions.<p>Also, the JIT needs to do that optimization anyways. If a class was compiled with Java 1.0, it might miss some optimizations introduced in the Java 27 compiler. To cover for that, the JVM 27 will need in it&#x27;s jit the optimizations which were missing from the 1.0 javac if it wants to keep making the code go faster.<p>That&#x27;s why the JVM developers have ultimately pushed to make javac pretty dumb and the JIT pretty smart. They can make much better optimizations in the JIT which are retroactive.
  • piinbinary1 hour ago
    The part of this that&#x27;s the most interesting to me is the fact that it is worthwhile for the compiler to expend the effort looking for this optimization opportunity. I would expect (x &lt;&lt; 2) &amp; -4 to be a fairly rare pattern, and even then removing the &amp; -4 only saves one or two assembly instructions.
    • ghusbands21 minutes ago
      Every optimisation like this increases the chance of other optimisations&#x2F;vectorisations being able to usefully fire, and sometimes these very specific cases are themselves from optimisations or type&#x2F;range restrictions.