[LLVMdev] Loop elimination with floating point counter.

Martin Geisse mgeisse at gmx.net
Thu Jan 8 09:49:05 PST 2009


Isn't "simplifying" the loop index to an integer also dependent on  
precision issues? The following loop is infinite:

for (float i=0.0; i<...; i+=1.0) {}

where ... is a large "integral" float literal, e.g. 2^40. At some  
point, adding 1.0 to the loop index would not cause any changes  
because of precision issues. However, if the float type is replaced  
by some sufficiently large integer type, the loop terminates.

The necessary reasoning may be simpler though.

Greetings,
Martin Geisse

On Jan 8, 2009, at 6:34 PM, Owen Anderson wrote:

> It's because with 1.0f, the loop index is simplified into an integer.
> With 1.2f, it isn't.  The loop deletion pass is dependent on the loop
> analyses being able to determine that the loop is finite, which they
> don't attempt to do for loops with floating point indices.  Attempting
> to do so would require additional reasoning about floating point
> precision issues.
>
> --Owen
>



More information about the llvm-dev mailing list