Skip to content

Fix CastOp canonicalization #317

@mtsamis

Description

@mtsamis

We currently have a canonicalization pattern for casts that fold multiple casts to a single one:

    // Composition.
    // %b = cast(%a) : A -> B
    //      cast(%b) : B -> C
    // ===> cast(%a) : A -> C

Looking at the explicit cast section in the specification, it is not generally safe to do so because we may lose information and get a cast whose scemantics are not well-defined.

E.g. consider that we have a value bit<8> x and then the casts (int<16>)(bit<16>) x and (int<16>)(int<8>) x. Both of them will be folded into cast x : b8 -> i16 but the first one does zero extension whereas the second one does sign extension.

We need to adjust the canonicalization pattern to only fold cases that preserve the original meaning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions