Stream: git-wasmtime

Topic: wasmtime / issue #11578 Cranelift: missing optimization o...


view this post on Zulip Wasmtime GitHub notifications bot (Aug 30 2025 at 04:12):

playX18 opened issue #11578:

Thanks for filing an issue! Please fill out the TODOs below.

.clif Test Case

function %a(i64) -> i64 {
block0(v2: i64):
    v3 = band_imm v2, -562949953421310
    v4 = icmp_imm eq v3, 0
    v5 = iconst.i64 6
    v6 = iconst.i64 7
    v7 = select v4, v6, v5  ; v6 = 7, v5 = 6
    v8 = icmp_imm eq v7, 6
    brif v8, block2, block1

block1:
    v9 = iconst.i64 100
    jump block3(v9)

block2:
    v10 = iconst.i64 101
    jump block3(v10)

block3(v11: i64):
    return v11
}

Steps to Reproduce

1) Have a code that generates icmp + select and then generates another icmp together with brif
2) Compile

Expected Results

There is potential rewrite possible here where select and icmp can be removed to simply checking result of v3 or v4 in the snippet above.

Actual Results

Code snippet above will generate x86 code with test, cmove, test, jne sequence which is not optimal.

   7:   41 b9 06 00 00 00       mov    $0x6,%r9d
   d:   48 85 15 2c 00 00 00    test   %rdx,0x2c(%rip)        # 40 <.Lfn0+0x40>
  14:   49 89 d3                mov    %rdx,%r11
  17:   4c 0f 44 0d 29 00 00    cmove  0x29(%rip),%r9        # 48 <.Lfn0+0x48>
  1e:   00
  1f:   49 83 f9 06             cmp    $0x6,%r9
  23:   0f 84 0d 00 00 00       je     36 <.Lfn0+0x36>

Versions and Environment

Cranelift version or commit: 0.123.1

Operating system: Fedora 42

Architecture: x86_64

view this post on Zulip Wasmtime GitHub notifications bot (Aug 30 2025 at 04:12):

playX18 added the bug label to Issue #11578.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 30 2025 at 04:12):

playX18 added the cranelift label to Issue #11578.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 30 2025 at 04:15):

alexcrichton removed the bug label from Issue #11578.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 30 2025 at 04:15):

alexcrichton added the cranelift:goal:optimize-speed label to Issue #11578.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 30 2025 at 04:15):

alexcrichton commented on issue #11578:

Slightly more backgrond on Zulip too

view this post on Zulip Wasmtime GitHub notifications bot (Aug 30 2025 at 21:30):

cfallin commented on issue #11578:

@playX18 could you clarify a bit more what rewrite you would expect here? There are at least two that are conceptually possible:


Last updated: Dec 06 2025 at 07:03 UTC