Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Three nested loops result in erroneous control flow #30

Open
tomiaijo opened this issue Jul 12, 2016 · 0 comments
Open

Three nested loops result in erroneous control flow #30

tomiaijo opened this issue Jul 12, 2016 · 0 comments

Comments

@tomiaijo
Copy link

While testing simple OpenCL image kernels through the HSAIL LLVM I noticed that three nested loops cause the outer loop to branch incorrectly. More specifically, the loop variable is incremented every other iteration of the outer loop. Attached is a simple OpenCL kernel that reproduces the issue. The issue persists up to -O2, but is not present when using -O3.

For this kernel, the HSAIL LLVM create the following outer loop structure (complete HSAIL attached):

…
@BB0_2:
    mov_b32 $s5, 0;
    not_b1  $c1, $c1;
    cbr_b1  $c1, @BB0_3;
    br  @BB0_7;
…
@BB0_7:
    add_u32 $s4, $s4, 1;
    cmp_ne_b1_s32   $c2, $s4, $s0;
    cbr_b1  $c2, @BB0_2;

The boolean c1 is negated on each iteration, but only every other iteration increments the outer loop variable $s4. It seems that the not clause is related to a check that asserts that the outer loop is executed at all (in this case, that x_size > -1).

Pull request #29 fixes this simple case, but more thorough control flow analysis is required to detect all variable uses inside loops.

kernel.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant