ind variable

Hello,

I have this piece of code:
int main() {
int m = 0;
// int i, j, k;
// int N = f()%10;
for (int l = 0; l < 1000; l+=4)
printf(“%d”, l);

I am sure, that llvm is capable to convert this into canonical induction variable, but even with O3
define i32 @main() #0 {
br label %2

; :1 ; preds = %2
ret i32 0

; :2 ; preds = %0, %2
%l.01 = phi i32 [ 0, %0 ], [ %4, %2 ]
%3 = tail call i32 (i8*, …) @printf(i8* nonnull getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %l.01)
%4 = add nuw nsw i32 %l.01, 4
%5 = icmp slt i32 %4, 1000
br i1 %5, label %2, label %1
}

I have this assembler.

I know there is indvars2 pass ( it is under llvm license but used only in LegUp project - as I understood, surfing the Internet), which is good in changing induction variables.

How can I achieve that this cycle will have a canonical indvar?

The files of this strange pass are described here http://reviews.legup.org/rLEGUP54ca7c2bb15d84116baf47bce67256d3803720d9 . I wonderwhy the most uptodate -indvars pass can’t do the same.

This support was removed years ago from indvars. We don't need canonical
induction variables any more as all analysis are done on SCEVs. The SCEV
generator can transform them even without the need for explicit
canonical induction variables.

Best,
Tobias

SCEV , seems to me that this is a little disadvantage ( I am not an expert by now in llvm, but think so), does not keep a cmp instruction, where someone can find a value , with which an induction variable is compared. When it is impossible to determine a trip count, that information can be useful ( hope not only for me). Still after receiving a block where this instruction is, it is not really hard to find the ICmp, but still…

…or maybe the second operand of ICmp

Could you also please share , how to process SCEV - it dump useful information , but can I somehow extract for example that basic block, which it is mentioning?

Could you please clarify for me: was the elimination of this pass also due to some performance issues? So, if I will insert this pass now and perform modification of the graph, will be there any performance impact?

In certain rare (but AFAIR important) cases the indvar canonicalization
reduced performance and LLVM was not successful in recovering the
optimal IR during later strength reduciton passes.

Best,
Tobias