Skip to content

Cranelift: Misoptimization of imul + ireduce #7999

@bjorn3

Description

@bjorn3

.clif Test Case

set opt_level=speed
target x86_64

function u0:11(i8) -> i8 system_v {
block0(v0: i8):
    v1 = uextend.i64 v0
    v2 = imul_imm v1, 256
    v3 = ireduce.i8 v2
    return v3
}

Steps to Reproduce

  • Compile reproducing test case with opt_level=speed.

Expected Results

The function unconditionally returns 0.

Actual Results

The function gets optimized to returning the argument:

function u0:11(i8) -> i8 system_v {
block0(v0: i8):
    return v0
}

Versions and Environment

Cranelift version or commit: 0.105 and 36fb62c

Operating system: N/A

Architecture: x86_64

Extra Info

Found by @cbeuw in rust-lang/rustc_codegen_cranelift#1460. Replacing i8 with i32 returns the correct result.

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