On 03/31/10 17:12, Jochen Wilhelmy wrote:> Hi!
>
> if I have this little function:
>
> float loopTest(float a, float b)
> {
> float x = 1.0f;
> int i = 0;
> if (a< b)
> goto l;
> for (i = 0; i< 10; ++i)
> {
> x *= a;
> l:
> x += b;
> }
> return x;
> }
>
> then llvm::LoopInfo does not detect that there is a loop.
> Is this a bug or is such a case not allowed?
>
> -Jochen
Hi Jochen,
I just compiled this to llvm-ir. In the IR as well as in the C code
there are two entries into the loop. One entering the loop over the
normal loop header and the other entering the loop using the l: mark.
Natural loops are defined to only have one header, the basic block that
dominates all basic blocks in the loop. This is the way how LoopInfo is
implemented, as it is stated at the top of include/llvm/LoopInfo.h. So
it is conceptional that the loop is not detected.
One way to change this is to create a pass, that transforms loops to
natural loops. This is possible, but generally involves code duplication.
Tobias