So I have this kernel which compiles fine when the indicated line is commented out, but causes this error when the line is in:

cvmsErrorCompilerFailure: LLVM compiler has failed to compile a function.

Any ideas why?

Code :
__kernel void Convolve(
        global const uint *img,
	write_only image2d_t newImg,
	const uint *filter, const int filterWidth, const int filterHeight,
	const int w, const int h, const int wpl)
{
        private const int gid = get_global_id(0);
	private const int x = gid%w;
	private const int y = gid/w;
	private const int halfWidth = filterWidth/2;
	private const int halfHeight = filterHeight/2;
 
	private uint sum = 0;
	private uint filterPointer = 0;
        private uint xfrom = (x-halfWidth)/32;
        private uint xto = (x+halfWidth)/32;
        private uint xwidth = xto - xfrom + 1;
        private uint imgCache[xwidth*(2*halfHeight+1)];
        private uint imgCachePtr = 0;
 
 
        for (int v=y-halfHeight; v<=y+halfHeight; v++)
            for (int u=xfrom; u<=xto; u++, imgCachePtr++)
            {
                bool outOfBounds = (v<0 || v>=h || u<0 || u>=wpl);
                int uu = outOfBounds ? 0 : u;
                int vv = outOfBounds ? 0 : v;
                uint val = img[wpl*vv + uu];
                val = outOfBounds ? 0 : val;
                imgCache[imgCachePtr] = val;
            }
 
 
	for (int v=0; v<filterHeight; v++)
		for (int u=0; u<filterWidth; u++, filterPointer++)
		{
			int yy = y + v - halfHeight;
			int xx = x + u - halfWidth;
                        bool outOfBounds = (yy < 0 || yy >= h || xx < 0 || xx >= w);
                        yy = outOfBounds ? 0 : yy;
                        //xx = outOfBounds ? 0 : xx;
                        imgCachePtr = v*xwidth + (xx/32) - xfrom;
 
                        uint buggy = (imgCache[imgCachePtr] >> (31 - (xx & 31))) & 0x01;
                        buggy = outOfBounds ? 0 : buggy;
                        buggy = 255 * (1 - buggy);
                        sum += buggy * filter[filterPointer]; // Why does this line cause a compile failure?????
 
                        uint val = (img[wpl*yy + xx/32] >> (31 - (xx & 31))) & 0x01;
                        val = outOfBounds ? 0 : val;
                        val = 255 * (1 - val);
                        sum += val * filter[filterPointer]; // .... and this line does not????
 
		}
 
 
	uint lowerBound = max( (uint)0, sum );
        uint upperBound = min( (uint)255, upperBound );
	write_imageui(newImg, (int2)(x, y),
		(uint4)( upperBound, 0, 0, 0) );
 
}