• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -indvars -S | FileCheck %s
2; RUN: opt -lcssa -loop-simplify -S < %s | opt -S -passes='require<targetir>,require<scalar-evolution>,require<domtree>,loop(indvars)'
3
4; Provide legal integer types.
5target datalayout = "n8:16:32:64"
6
7
8target triple = "x86_64-apple-darwin"
9
10; CHECK-LABEL: @loop_0
11; CHECK-LABEL: B18:
12; Only one phi now.
13; CHECK: phi
14; CHECK-NOT: phi
15; One trunc for the gep.
16; CHECK: trunc i64 %indvars.iv to i32
17; One trunc for the dummy() call.
18; CHECK-LABEL: exit24:
19; CHECK: trunc i64 {{.*}}lcssa.wide to i32
20define void @loop_0(i32* %a) {
21Prologue:
22  br i1 undef, label %B18, label %B6
23
24B18:                                        ; preds = %B24, %Prologue
25  %.02 = phi i32 [ 0, %Prologue ], [ %tmp33, %B24 ]
26  %tmp23 = zext i32 %.02 to i64
27  %tmp33 = add i32 %.02, 1
28  %o = getelementptr i32, i32* %a, i32 %.02
29  %v = load i32, i32* %o
30  %t = icmp eq i32 %v, 0
31  br i1 %t, label %exit24, label %B24
32
33B24:                                        ; preds = %B18
34  %t2 = icmp eq i32 %tmp33, 20
35  br i1 %t2, label %B6, label %B18
36
37B6:                                       ; preds = %Prologue
38  ret void
39
40exit24:                      ; preds = %B18
41  call void @dummy(i32 %.02)
42  unreachable
43}
44
45define void @loop_1(i32 %lim) {
46; CHECK-LABEL: @loop_1(
47 entry:
48  %entry.cond = icmp ne i32 %lim, 0
49  br i1 %entry.cond, label %loop, label %leave
50
51 loop:
52; CHECK: loop:
53; CHECK:  %indvars.iv = phi i64 [ 1, %loop.preheader ], [ %indvars.iv.next, %loop ]
54; CHECK:  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
55; CHECK:  [[IV_INC:%[^ ]+]] = add nsw i64 %indvars.iv, -1
56; CHECK:  call void @dummy.i64(i64 [[IV_INC]])
57
58  %iv = phi i32 [ 1, %entry ], [ %iv.inc, %loop ]
59  %iv.inc = add i32 %iv, 1
60  %iv.inc.sub = add i32 %iv, -1
61  %iv.inc.sub.zext = zext i32 %iv.inc.sub to i64
62  call void @dummy.i64(i64 %iv.inc.sub.zext)
63  %be.cond = icmp ult i32 %iv.inc, %lim
64  br i1 %be.cond, label %loop, label %leave
65
66 leave:
67  ret void
68}
69
70declare void @dummy(i32)
71declare void @dummy.i64(i64)
72