You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I noticed a bug fix in #456, which tries to fix wrongly optimizes away if condition.
But, I am still be able to trigger similar bugs through the following code:
import heterocl as hcl
def test_mask():
def two_stage(A):
var = hcl.scalar(0, "v", dtype=hcl.Int(32))
with hcl.if_(var == 0):
var.v = var - 33
hcl.print(var,"A\n")
with hcl.if_(var == -33):
hcl.print((var),"B\n")
with hcl.else_():
var.v = var - 1
# this condition should not be optimized away
with hcl.if_(var == 0):
hcl.print((),"B\n")
return A
A = hcl.placeholder((2,), "A", dtype=hcl.UInt(16))
s = hcl.create_schedule([A], two_stage)
print(hcl.lower(s))
Which should generate IR code like this:
produce v {
// attr [0] extern_scope = 0
for "stage_name"="v" (x, 0, 1) {
v[x] = 0
}
}
if ((v[0] == 0)) {
v[0] = (v[0] + -33)
print: v[0]
if ((v[0] == -33)) {
print: v[0]
}
} else {
v[0] = (v[0] + -1)
if ((v[0] == 0)) {
print:
}
}
But now, HeteroCL generates IR like this:
produce v {
// attr [0] extern_scope = 0
for "stage_name"="v" (x, 0, 1) {
v[x] = 0
}
}
if ((v[0] == 0)) {
v[0] = -33
print: 0
} else {
v[0] = (v[0] + -1)
if ((v[0] == 0)) {
print:
}
}
The second PrintStmt is optimized away, but its if condition could be met.
This bug is trigger by the code in IfThenElse pass in Simplify
The text was updated successfully, but these errors were encountered:
wyanzhao
changed the title
Bugs found in Simplify IfThenElse pass, due to overaggressive optimizations
Bug found in Simplify IfThenElse pass, due to overaggressive optimizations
Jun 8, 2022
import heterocl as hcl
def test_mask():
def two_stage(A):
var = hcl.scalar(1, "v", dtype=hcl.Int(32))
with hcl.if_(var != 1):
hcl.print(var,"A\n")
with hcl.else_():
var.v = var - 1
hcl.print((var),"B\n")
with hcl.if_(var == 0):
hcl.print((var),"C\n")
return A
A = hcl.placeholder((2,), "A", dtype=hcl.UInt(16))
s = hcl.create_schedule([A], two_stage)
print(hcl.lower(s))
if __name__ == "__main__":
test_mask()
The output is
produce v {
// attr [0] extern_scope = 0
for "stage_name"="v" (x, 0, 1) {
v[x] = 1
}
}
if ((v[0] != 1)) {
print: v[0]
} else {
v[0] = 0
print: 1
}
Correct output should be
produce v {
// attr [0] extern_scope = 0
for "stage_name"="v" (x, 0, 1) {
v[x] = 1
}
}
if ((v[0] != 1)) {
print: v[0]
} else {
v[0] = (v[0] + -1)
print: v[0]
if ((v[0] == 0)) {
print: 0
}
}
The if condition in the third Print Stmt can also be met.
Hi, I noticed a bug fix in #456, which tries to fix wrongly optimizes away if condition.
But, I am still be able to trigger similar bugs through the following code:
Which should generate IR code like this:
But now, HeteroCL generates IR like this:
The second Print Stmt is optimized away, but its if condition could be met.
This bug is trigger by the code in IfThenElse pass in Simplify
The text was updated successfully, but these errors were encountered: