Takashiidobe opened issue #14694:
.clifTest Casefunction %missing_division(i8) -> i8 { block0(v0: i8): v1 = iconst.i8 7 v10 = sdiv v0, v1 v2 = iconst.i8 0 return v2 }Steps to Reproduce
- compile on any architecture
Expected Results
the sdiv cannot trap and is dead, so i would expect something like return 0
Actual Results
for x86_64 I see:
push rbp mov rbp, rsp mov rax, rdi cbw mov esi, 7 idiv sil ; trap: int_ovf xor eax, eax mov rsp, rbp pop rbp retwith the trap comment so I assume it's not properly deleted
Versions and Environment
Cranelift version or commit: 0.136.2
Operating system: linux
Architecture: x86_64, though this happens on all architectures since this isn't lowering specific
Extra Info
https://github.com/bytecodealliance/wasmtime/issues/5908 seems to indicate that work was done to handle this problem already.
i32 and i64 already properly handle this case, i8 and i16 do not.
I'm assuming that just extending i8 and i16 to i32 is a cheap fix for this particular problem, since they both just emit, which deletes the division entirely
push rbp mov rbp, rsp xor eax, eax mov rsp, rbp pop rbp ret
Takashiidobe added the bug label to Issue #14694.
Takashiidobe added the cranelift label to Issue #14694.
alexcrichton added the cranelift:goal:optimize-speed label to Issue #14694.
alexcrichton closed issue #14694:
.clifTest Casefunction %missing_division(i8) -> i8 { block0(v0: i8): v1 = iconst.i8 7 v10 = sdiv v0, v1 v2 = iconst.i8 0 return v2 }Steps to Reproduce
- compile on any architecture
Expected Results
the sdiv cannot trap and is dead, so i would expect something like return 0
Actual Results
for x86_64 I see:
push rbp mov rbp, rsp mov rax, rdi cbw mov esi, 7 idiv sil ; trap: int_ovf xor eax, eax mov rsp, rbp pop rbp retwith the trap comment so I assume it's not properly deleted
Versions and Environment
Cranelift version or commit: 0.136.2
Operating system: linux
Architecture: x86_64, though this happens on all architectures since this isn't lowering specific
Extra Info
https://github.com/bytecodealliance/wasmtime/issues/5908 seems to indicate that work was done to handle this problem already.
i32 and i64 already properly handle this case, i8 and i16 do not.
I'm assuming that just extending i8 and i16 to i32 is a cheap fix for this particular problem, since they both just emit, which deletes the division entirely
push rbp mov rbp, rsp xor eax, eax mov rsp, rbp pop rbp ret
Last updated: Oct 31 2026 at 23:03 UTC