1 ; RUN: opt < %s -indvars -S | FileCheck %s
3 ; This tests that the IV is not recomputed outside of the loop when it is known
4 ; to be computed by the loop and used in the loop any way. In the example below
5 ; although a's value can be computed outside of the loop, there is no benefit
6 ; in doing so as it has to be computed by the loop anyway.
8 ; extern void func(unsigned val);
10 ; void test(unsigned m)
14 ; for (int i=0; i<186; i++) {
22 declare void @func(i32)
25 define void @test(i32 %m) nounwind uwtable {
29 for.body: ; preds = %for.body, %entry
30 %i.06 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
31 %a.05 = phi i32 [ 0, %entry ], [ %add, %for.body ]
32 %add = add i32 %a.05, %m
33 ; CHECK: tail call void @func(i32 %add)
34 tail call void @func(i32 %add)
35 %inc = add nsw i32 %i.06, 1
36 %exitcond = icmp eq i32 %inc, 186
37 br i1 %exitcond, label %for.end, label %for.body
39 for.end: ; preds = %for.body
41 ; CHECK-NOT: mul i32 %m, 186
42 ; CHECK:%add.lcssa = phi i32 [ %add, %for.body ]
43 ; CHECK-NEXT: tail call void @func(i32 %add.lcssa)
44 tail call void @func(i32 %add)
48 ; CHECK-LABEL: @test2(
49 define i32 @test2(i32 %m) nounwind uwtable {
53 for.body: ; preds = %for.body, %entry
54 %i.06 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
55 %a.05 = phi i32 [ 0, %entry ], [ %add, %for.body ]
56 %add = add i32 %a.05, %m
57 ; CHECK: tail call void @func(i32 %add)
58 tail call void @func(i32 %add)
59 %inc = add nsw i32 %i.06, 1
60 %exitcond = icmp eq i32 %inc, 186
61 br i1 %exitcond, label %for.end, label %for.body
63 for.end: ; preds = %for.body
65 ; CHECK-NOT: mul i32 %m, 186
66 ; CHECK:%add.lcssa = phi i32 [ %add, %for.body ]
67 ; CHECK-NEXT: ret i32 %add.lcssa