Minimal test case: in the top-level else branch, the var has been updated before going in another if statement. Namely, the second with hcl.if_(var == 0) is not always false, and should not be optimized away.
def two_stage(A):
var = hcl.scalar(0, "v", dtype=hcl.UInt(32))
var.v = 1
with hcl.if_(var == 0):
hcl.print((),"A\n")
with hcl.else_():
var.v = var - 1
with hcl.if_(var == 0):
hcl.print((),"B\n")
return A
This is the buggy IR generated by HCL before the ifx.
For fixing issues
Fixed issue: #450
Detailed description:
Minimal test case: in the top-level
else
branch, thevar
has been updated before going in another if statement. Namely, the secondwith hcl.if_(var == 0)
is not always false, and should not be optimized away.This is the buggy IR generated by HCL before the ifx.
Here is the expected IR that should be generated after applying the fix.
Link to the tests: tests/issues/test_issue_450.py