Skip to content

Cranelift: "constant immediate is out of bounds" #9041

Open
@Kmeakin

Description

@Kmeakin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior in the current implementation that needs fixingcraneliftIssues related to the Cranelift code generator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions