Simoffsky opened issue #10994:
Cranelift fails to eliminate a dead conditional branch in a case where the condition is statically known to be false due to constant folding.
godbolt link (look at $process_rows).
Input WASM getted by using C++ Wasmtime API
(module (func $process_rows (param i32 i32) (result i32) block i32.const 0 i32.eqz br_if 0 local.get 0 i32.const 1 i32.shl local.get 0 i32.const 1 i32.add local.get 0 i32.const 2 i32.gt_s select local.get 0 i32.add local.set 0 end local.get 0 i32.const 1 i32.add))Expected behavior
Since
i32.const 0is always equal to zero, the result ofi32.eqzis always 1, andbr_if 0is guaranteed to be taken unconditionally. Therefore, all code after the branch inside the block is dead and should be removed.xor esi, esi test esi, esi je <after_block> ; this is always false, should not exist mov rax, rdx ; dead code shl eax, 0x1 lea edi, [rdx + 0x1] cmp edx, 0x2 cmovg edi, eax add edx, edi lea eax, [rdx + 0x1]Versions and Environment
Cranelift version or commit: Wasmtime 22.0.0
Operating system: macos, linux (debian)
Architecture: (arm, x64)
Simoffsky added the bug label to Issue #10994.
Simoffsky added the cranelift label to Issue #10994.
Simoffsky edited issue #10994:
Cranelift fails to eliminate a dead conditional branch in a case where the condition is statically known to be false due to constant folding.
godbolt link (look at $process_rows).
Input WASM
(module (func $process_rows (param i32 i32) (result i32) block i32.const 0 i32.eqz br_if 0 local.get 0 i32.const 1 i32.shl local.get 0 i32.const 1 i32.add local.get 0 i32.const 2 i32.gt_s select local.get 0 i32.add local.set 0 end local.get 0 i32.const 1 i32.add))Expected behavior
Since
i32.const 0is always equal to zero, the result ofi32.eqzis always 1, andbr_if 0is guaranteed to be taken unconditionally. Therefore, all code after the branch inside the block is dead and should be removed.xor esi, esi test esi, esi je <after_block> ; this is always false, should not exist mov rax, rdx ; dead code shl eax, 0x1 lea edi, [rdx + 0x1] cmp edx, 0x2 cmovg edi, eax add edx, edi lea eax, [rdx + 0x1]Versions and Environment
Cranelift version or commit: Wasmtime 22.0.0
Operating system: macos, linux (debian)
Architecture: (arm, x64)
cfallin closed issue #10994:
Cranelift fails to eliminate a dead conditional branch in a case where the condition is statically known to be false due to constant folding.
godbolt link (look at $process_rows).
Input WASM
(module (func $process_rows (param i32 i32) (result i32) block i32.const 0 i32.eqz br_if 0 local.get 0 i32.const 1 i32.shl local.get 0 i32.const 1 i32.add local.get 0 i32.const 2 i32.gt_s select local.get 0 i32.add local.set 0 end local.get 0 i32.const 1 i32.add))Expected behavior
Since
i32.const 0is always equal to zero, the result ofi32.eqzis always 1, andbr_if 0is guaranteed to be taken unconditionally. Therefore, all code after the branch inside the block is dead and should be removed.xor esi, esi test esi, esi je <after_block> ; this is always false, should not exist mov rax, rdx ; dead code shl eax, 0x1 lea edi, [rdx + 0x1] cmp edx, 0x2 cmovg edi, eax add edx, edi lea eax, [rdx + 0x1]Versions and Environment
Cranelift version or commit: Wasmtime 22.0.0
Operating system: macos, linux (debian)
Architecture: (arm, x64)
cfallin commented on issue #10994:
We don't have any branch-folding optimizations at the moment, so this result is expected. #6106 covers tracking this possible enhancement, I believe, so I'll close as a duplicate of that tracking issue.
cfallin closed issue #10994:
Cranelift fails to eliminate a dead conditional branch in a case where the condition is statically known to be false due to constant folding.
godbolt link (look at $process_rows).
Input WASM
(module (func $process_rows (param i32 i32) (result i32) block i32.const 0 i32.eqz br_if 0 local.get 0 i32.const 1 i32.shl local.get 0 i32.const 1 i32.add local.get 0 i32.const 2 i32.gt_s select local.get 0 i32.add local.set 0 end local.get 0 i32.const 1 i32.add))Expected behavior
Since
i32.const 0is always equal to zero, the result ofi32.eqzis always 1, andbr_if 0is guaranteed to be taken unconditionally. Therefore, all code after the branch inside the block is dead and should be removed.xor esi, esi test esi, esi je <after_block> ; this is always false, should not exist mov rax, rdx ; dead code shl eax, 0x1 lea edi, [rdx + 0x1] cmp edx, 0x2 cmovg edi, eax add edx, edi lea eax, [rdx + 0x1]Versions and Environment
Cranelift version or commit: Wasmtime 22.0.0
Operating system: macos, linux (debian)
Architecture: (arm, x64)
Last updated: Dec 06 2025 at 06:05 UTC