Skip to content

Bug lowering scf.IfElse #435

Open
Open
@weinbe58

Description

@weinbe58

The following lowering doesn't look right to me:

from kirin.prelude import structual

@structural
def test(cond: bool) -> int:
    c = 0
    if cond:
        c = 1
    else:
        return 2
        
    return c

currently lowers to:

func.func @test(cond : !py.bool) -> !py.int {
  ^0(%test_self, %cond_1):
  │    %c = py.constant.constant 0 : !py.int
  │ %cond = scf.if %cond_1 : !py.bool {
  │         │ ^1(%cond_2):
  │         │ │ scf.yield %cond_2 : !py.bool
  │         } else {
  │         │ ^2(%cond_3):
  │         │ │ %0 = py.constant.constant 2 : !py.int
  │         │ │      func.return %0
  │         } -> purity=False
  │         func.return %c
} // func.func test

shuold be something more like:

func.func @test(cond : !py.bool) -> !py.int {
  ^0(%test_self, %cond_1):
  │    %c = py.constant.constant 0 : !py.int
  │ %cond, %c_1 = scf.if %cond_1 : !py.bool {
  │                  │ ^1(%cond_2):
  │                  │ │ %c_2 = py.constant 1
  │                  │ │ scf.yield %cond_2 : !py.bool, %c_2 : !py.int
  │                  } else {
  │                  │ ^2(%cond_3):
  │                  │ │ %0 = py.constant.constant 2 : !py.int
  │                  │ │      func.return %0
  │                  } -> purity=False
  │         func.return %c_1
} // func.func test

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdialect:scfstructural control flow related issuepython loweringpython lowering related issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions