# How HotSpot's JIT Learned to Reason About Bits and Delete Code

Original title: The mask that compiles to nothing: how HotSpots JIT learned to reason about bits

> Hacker News story 48798566 · language: en · submitted 2026-07-05
> Web version: https://zeli.app/story/48798566
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 21 · by [rowbin](<https://news.ycombinator.com/user?id=rowbin>) · 💬 0
[original](<https://questdb.com/blog/jvm-jit-known-bits/>) · [HN discussion](<https://news.ycombinator.com/item?id=48798566>)

## Summary

I explore how HotSpot's C2 compiler evolved beyond simple numeric ranges to track individual bit states. By introducing 'known bits' alongside value ranges, the JIT can now prove that certain bitwise operations, like masking after a shift, are redundant. This refinement allows the compiler to safely eliminate unnecessary instructions, turning complex expressions into efficient, minimal code.

## Key quote

> A range can say the value is small, but it can't say the value is even, let alone a multiple of four.

## HN discussion (0 comments)

### [piinbinary](<https://news.ycombinator.com/item?id=48872058>)

> The part of this that'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 << 2) & -4 to be a fairly rare pattern, and even then removing the & -4 only saves one or two assembly instructions.

### [CalChris](<https://news.ycombinator.com/item?id=48872452>)

> Why is this known bits optimization being done by the JIT rather than the Java compiler?

---

## Cite

- Page: https://zeli.app/story/48798566
- Date: 2026-07-05
- Source: questdb.com (https://questdb.com/blog/jvm-jit-known-bits/)
- Hacker News: https://news.ycombinator.com/item?id=48798566

## Other languages

- zh: https://zeli.app/zh/story/48798566 · markdown: https://zeli.app/zh/story/48798566.md
- ja: https://zeli.app/ja/story/48798566 · markdown: https://zeli.app/ja/story/48798566.md
- ko: https://zeli.app/ko/story/48798566 · markdown: https://zeli.app/ko/story/48798566.md
- de: https://zeli.app/de/story/48798566 · markdown: https://zeli.app/de/story/48798566.md
- es: https://zeli.app/es/story/48798566 · markdown: https://zeli.app/es/story/48798566.md
