spcl / dace

DaCe - Data Centric Parallel Programming
http://dace.is/fast
BSD 3-Clause "New" or "Revised" License
487 stars 121 forks source link

[Codegen] Control Flow Detection Generates Infinite Goto-Loop with Continue #1586

Open phschaad opened 2 months ago

phschaad commented 2 months ago

When generating code for an SDFG with a single for loop containing a continue statement, codegen generates an infinite loop by inserting a wrongful goto in place of a continue statement. The behavior occurs with Python 3.7, automatic simplification disabled, and control flow detection enabled (as is the default).

A minimal example SDFG that exposes the issue is shown here: image

The following code is generated:

void __program_test_for_continue_internal(test_for_continue_state_t*__state, int * __restrict__ A)
{
    long long i;
    for (i = 0; (i < 10); i = i+1) {
        if (((i % 2) == 0)) {
            if (false) {
            }
            __state_0_s_6:;
        }
        {
            {
                int o1;
                ///////////////////
                // Tasklet code (assign)
                o1 = i;
                ///////////////////
                A[i] = o1;
            }
        }
        goto __state_0_s_6;
    }
}

Evidently, the goto to label __state_0_s_6 causes an infinite loop. The expected behavior would be that:

The issue can be reproduced by running the test found here: https://github.com/spcl/dace/blob/cfg_detection_infinite_loop_bug/tests/control_flow_test.py#L351

Note: This is a blocking issue for one of the final Loops PRs as it causes a single test to hang: https://github.com/spcl/dace/pull/1475