Stream: general

Topic: Can constants be propagated to jump tables in cranelift IR?


view this post on Zulip Stanley (Apr 14 2026 at 05:55):

Hello, I am working on a JIT compiler for a stack-based language similar to Forth.

I have noticed that Cranelift seems to be generating this IR (after calling Context::optimize):

block6:
    v32 = iconst.i32 0
    br_table v32, block1, [block2, block3, block4, block5]  ; v32 = 0

And, Cranelift is emitting x86 instructions for the jump table, even though it knows at compile time which branch will be taken, since the value of v32 is known at compile time. Is this an optimization that the cranelift compiler cannot make, or am I doing something incorrectly? Thanks.

view this post on Zulip Notification Bot (Apr 14 2026 at 13:21):

This topic was moved to #cranelift > Can constants be propagated to jump tables in cranelift IR? by fitzgen (he/him).


Last updated: May 03 2026 at 22:13 UTC