[llvm-dev] loop canonical variables

Sanjoy Das via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 26 11:40:25 PDT 2017


Hi Anastasiya,

On Wed, Jul 26, 2017 at 4:44 AM, Anastasiya Ruzhanskaya via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> Still, there a question:
> 1) does loop analysis always find only outermost loop? I can't make it
> finding all innermost ones (LoopInfo &LI =
> getAnalysis<LoopInfoWrapperPass>().getLoopInfo()). With other means it is
> possible,but not so convenient;

LoopInfo returns the roots of the loop nest.  For each llvm::Loop in LoopInfo,
Loop::getSubLoops() returns the set of loops totally contained within the
llvm::Loop.

> 2) is the trip count value determined only when there is one exit block (I
> have seen such assert in code, but maybe there are other functions, that can
> overcome this difficulty)? In this example I have not fully optimized
> version but still I can't be sure that this will not happen even after full
> optimization pass:
>
> define i32 @main() #0 {
>   br label %1
>
> ; <label>:1                                       ; preds = %0, %4
>   %i.03 = phi i32 [ 0, %0 ], [ %5, %4 ]
>   %a.02 = phi i32 [ 0, %0 ], [ %2, %4 ]
>   %2 = add i32 %a.02, %i.03
>   %3 = icmp sgt i32 %i.03, 7
>   br i1 %3, label %.loopexit, label %4
>
> ; <label>:4                                       ; preds = %1
>   %5 = add nsw i32 %i.03, 1
>   %6 = icmp ne i32 %5, 10
>   br i1 %6, label %1, label %.loopexit
>
> .loopexit:                                        ; preds = %4, %1
>   %a.1 = phi i32 [ %2, %1 ], [ %2, %4 ]
>   ret i32 %a.1
> }
>
> the c code
>
>     unsigned a = 0;
>     for (int i = 0; i != 10; i++) {
>       a+=i;
>       if (i > 7)
>         break;
>     }
>     return a;

I think SCEV can be made smarter in this case -- can you please file a
bug?  For the time being, you can consider using
getMaxBackedgeTakenCount.

-- Sanjoy


More information about the llvm-dev mailing list