while(true) loop optimized out huh

I’m working on a kernel that uses an infinite ( while(true) ) loop, with a break somewhere in the middle indicating when the process should stop. The number of iterations is not yet known before the loop, and would be very expensive to calculate.

For some reason, nvcc compiles this loop to no code at all, as it’s not in the PTX. It just plainly throws it away. I don’t get it…

Does anyone have an idea why this is happening?

never mind, it seems that some much deeper problem is in action here, more like a compiler bug but not specific to infinite loops

Hi,

IMHO it’s a compiler bug.

I discovered at least three compiler bugs not long ago. I am going to post my findings here in forum.

You could try to use this workaround.

I tested it on x86-64 Linux.

int condition_var = 1;

while (condition_var == 1)

{

// ...

// do something useful

// ...

// ...

//  'condition' is the break condition

if (condition) condition_var = 0;

// ...

// do something

}