diff --git a/loopy/kernel/creation.py b/loopy/kernel/creation.py index c6618d62f7543fd2bc5461762ed19714e998fc14..b1e7c3194c97eb84ec916833d3b622cacbfbe7d2 100644 --- a/loopy/kernel/creation.py +++ b/loopy/kernel/creation.py @@ -896,7 +896,8 @@ def parse_instructions(instructions, defines): obj = insn_options_stack.pop() #if this object is the end of an if statement if obj['predicates'] == if_predicates_stack[-1]["insn_predicates"] and\ - if_predicates_stack[-1]["insn_predicates"]: + if_predicates_stack[-1]["insn_predicates"] and\ + obj['within_inames'] == if_predicates_stack[-1]['within_inames']: if_predicates_stack.pop() continue diff --git a/test/test_loopy.py b/test/test_loopy.py index 397d4832b0004725d7fc1559569c352861cb033e..066de6292411d5f38fb52c9be8dcd2328786ea03 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -2034,6 +2034,37 @@ def test_if_else(ctx_factory): out_ref[4::6] = 11 out_ref[2::6] = 3 + knl = lp.make_kernel( + "{ [i,j]: 0<=i,j<50}", + """ + for i + if i < 25 + for j + if j % 2 == 0 + a[i, j] = 1 + else + a[i, j] = 0 + end + end + else + for j + if j % 2 == 0 + a[i, j] = 0 + else + a[i, j] = 1 + end + end + end + end + """ + ) + + evt, (out,) = knl(queue, out_host=True) + + out_ref = np.zeros((50, 50)) + out_ref[:25, 0::2] = 1 + out_ref[25:, 1::2] = 1 + assert np.array_equal(out_ref, out)