Skip to content

Commit b994308

Browse files
authored
fix constprop multi value (#394)
based on #392 but also fix another incorrect return.
1 parent d10b726 commit b994308

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/kirin/analysis/const/prop.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ def frame_eval(
7373
if types.is_tuple_of(values, Value):
7474
return self.try_eval_const_pure(frame, node, values)
7575

76-
if node.has_trait(ir.Pure):
77-
return (Unknown(),) # no implementation but pure
78-
# not pure, and no implementation, let's say it's not pure
79-
frame.frame_is_not_pure = True
80-
return (Unknown(),)
76+
if not node.has_trait(ir.Pure):
77+
# not pure, and no implementation, let's say it's not pure
78+
frame.frame_is_not_pure = True
79+
return tuple(Unknown() for _ in node._results)
8180

8281
ret = method(self, frame, node)
8382
if node.has_trait(ir.IsTerminator) or node.has_trait(ir.Pure):

test/analysis/dataflow/constprop/test_multi_return.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ def __init__(self, *args: ir.SSAValue):
2121
)
2222

2323

24+
@statement(dialect=dialect)
25+
class MultiReturnNotPure(ir.Statement):
26+
traits = frozenset({lowering.FromPythonCall()})
27+
inputs: tuple[ir.SSAValue] = info.argument(types.Any)
28+
29+
def __init__(self, *args: ir.SSAValue):
30+
super().__init__(
31+
args=args,
32+
result_types=tuple(arg.type for arg in args),
33+
args_slice={"inputs": slice(None)},
34+
)
35+
36+
2437
@ir.dialect_group(structural_no_opt.add(dialect))
2538
def dialect_group_test(self):
2639
fold = Fold(self)
@@ -40,6 +53,7 @@ def test_multi_return_default_prop():
4053
(b := py.Constant(2)),
4154
(res := MultiReturnStatement(a.result, b.result)),
4255
(return_result := ilist.New((res.results[0], res.results[1]))),
56+
(res := MultiReturnNotPure(a.result, b.result)),
4357
(func.Return(return_result.result)),
4458
]
4559

0 commit comments

Comments
 (0)