bytecodealliance / bytecodealliance/wasmtime

Cranelift: "constant immediate is out of bounds"

Open
#9,041 2 comments 0 reactions 0 assignees View on GitHub
bug cranelift
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 19h
Merged PRs (30d)
121

Description

Adding this optimization to `codegen/src/opts/icmp.isle`

```
;; sge(x, c) == sgt(x, c-1), for c != SMIN.
(rule (simplify (sge (fits_in_64 (ty_int bty)) x (iconst cty (u64_from_imm64 c))))
(if-let $false (u64_eq c (ty_smin cty)))
(sgt bty x (iconst cty (imm64 (u64_sub c 1)))))
```

Triggers a verification error when optimizing `filetests/filetests/egraph/icmp-parameterized.clif`:
```
FAIL filetests/filetests/egraph/icmp-parameterized.clif: optimize

Caused by:
function %icmp_sgt_umax(i32) -> i8 fast {
block0(v0: i32):
v5 = iconst.i32 -1
; ^~~~~~~~~~~~~~~~~~
; error: inst5 (v5 = iconst.i32 -1): constant immediate is out of bounds

v10 = icmp sgt v0, v5 ; v5 = -1
return v10
}

; 1 verifier error detected (see above). Compilation aborted.
```

I suspect somewhere the immediate is being sign extended when it should be zero extended

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.