#Burst does not see an optimization that looks quite simple

1 messages · Page 1 of 1 (latest)

rose venture
#

Hello! I'm trying to understand what Burst can optimize and how so I tried this code :

[BurstCompile]
private static int BurstMandel(float x, float y, int iter)
{
    int i = 0;
    for (int _ = 0; _ < TIME_MULTIPLY; _++)
    {
        float z_real = 0;
        float z_imag = 0;
        float z_real_tmp;
        float z_imag_tmp;
        i = 0;
        while (i < iter)
        {
            z_real_tmp = z_real * z_real - z_imag * z_imag + x;
            z_imag_tmp = 2 * z_real * z_imag + y;
            if (z_real_tmp * z_real_tmp + z_imag_tmp * z_imag_tmp >= 4) break;
            z_real = z_real_tmp;
            z_imag = z_imag_tmp;
            i++;
        }
    }
    return i;
}

I thought Burst would understand that the for loop is completely useless and just here to make it waste time (it just does the same exact thing TIME_MULTIPLY times, doing it once is enough to have the right result) but apparently it does not.
Not to criticize or anything like that, I'm just curious as to why 🙂
Is there something I'm doing wrong that causes it to not understand that? Or can it simply not do that kind of optimisations?

I'm even more surprised to see that, after trying the same in python, Numba (a python module)'s JIT compiler does see the optimization : no matter how much TIME_MULTIPLIER is, the function takes the same time 🙂
So it is apparently possible 🙂

topaz cliff
#

Yeah, that seems weird.
I would presume it should see that there are no free variables or side effects, and the iterator is not used in the loop.
I think it would be more suitable for a bug report, maybe they've just overlooked this.

lunar solstice
#

do LLVM has this optimization at all?

quick citrus
#

you could try the same thing in clang and see if it figures it out

#

also burst does have some optimization settings that can cause it to try more or less hard to optimize, trading off with compilation time

rose venture
rose venture
quick citrus
rose venture