Skip to content

Fold pass removes if / elif when it shouldn't #416

Open
@david-pl

Description

@david-pl

MWE:

from kirin.prelude import structural_no_opt
from kirin.passes import Fold

@structural_no_opt
def main(n: int):
    x = 0

    if x == n:
        x += 1
    elif x == n+1:
        x += 3
    
    return x

main.print()

Fold(main.dialects)(main)

main.print()

Output:

func.func main(!py.int) -> !Any {
  ^0(%main_self, %n):
  │ %x = py.constant.constant 0 : !py.intfunc.return %x
} // func.func main

Things work correctly if you replace the elif by another if, but it's not technically identical since x is updated in-place which might lead to the second if to be True..

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