hi, <br><br>you could try the getBackedgeTakenCount function of ScalarEvolution.<br><br>opt -scalar-evolution -analyze<br>define void @f(i64* nocapture %a, i64 %N) nounwind {<br>entry:<br> %0 = icmp sgt i64 %N, 0 ; <i1> [#uses=1]<br>
br i1 %0, label %bb, label %return<br><br>bb: ; preds = %bb, %entry<br> %1 = phi i64 [ 0, %entry ], [ %2, %bb ] ; <i64> [#uses=3]<br> %scevgep = getelementptr i64* %a, i64 %1 ; <i64*> [#uses=1]<br>
store i64 %1, i64* %scevgep, align 8<br> %2 = add nsw i64 %1, 1 ; <i64> [#uses=2]<br> %exitcond = icmp eq i64 %2, %N ; <i1> [#uses=1]<br> br i1 %exitcond, label %return, label %bb<br>
<br>return: ; preds = %bb, %entry<br> ret void<br>}<br>Printing analysis 'Scalar Evolution Analysis' for function 'f':<br>Classifying expressions for: @f<br> %0 = icmp sgt i64 %N, 0 ; <i1> [#uses=1]<br>
--> %0<br> %1 = phi i64 [ 0, %entry ], [ %2, %bb ] ; <i64> [#uses=3]<br> --> {0,+,1}<%bb> Exits: (-1 + %N)<br> %scevgep = getelementptr i64* %a, i64 %1 ; <i64*> [#uses=1]<br>
--> {%a,+,sizeof(i64)}<%bb> Exits: (((-1 + %N) * sizeof(i64)) + %a)<br> %2 = add nsw i64 %1, 1 ; <i64> [#uses=2]<br> --> {1,+,1}<%bb> Exits: %N<br>
%exitcond = icmp eq i64 %2, %N ; <i1> [#uses=1]<br> --> %exitcond Exits: <<Unknown>><br>Determining loop execution counts for: @f<br>Loop %bb: backedge-taken count is (-1 + %N)<br>
Loop %bb: max backedge-taken count is (-1 + %N)<br><br>--best regares<br>ether<br>