1; RUN: opt -loop-unroll-and-jam -allow-unroll-and-jam -verify-loop-info < %s -S | FileCheck %s
2; RUN: opt -passes='loop-unroll-and-jam,verify<loops>' -allow-unroll-and-jam < %s -S | FileCheck %s
3
4; Check that the newly created loops to not fail to be added to LI
5; This test deliberately disables UnJ on the middle loop, performing it instead on the
6; outer of 3 nested loops. The (new) inner loops need to be added to LI.
7
8target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
9
10define i32 @test() {
11; CHECK-LABEL: test
12; CHECK:       for.cond17.preheader:
13; CHECK:    br label %for.cond20.preheader
14; CHECK:       for.cond20.preheader:
15; CHECK:    br label %for.cond23.preheader
16; CHECK:       for.cond23.preheader:
17; CHECK:    br label %for.body25
18; CHECK:       for.body25:
19; CHECK:    br i1 [[CMP24:%.*]], label %for.body25, label %for.inc45
20; CHECK:       for.inc45:
21; CHECK:    br label %for.body25.1
22; CHECK:       for.inc48:
23; CHECK:    br i1 [[CMP18_3:%.*]], label %for.cond20.preheader, label %for.end50
24; CHECK:       for.end50:
25; CHECK:    ret i32 0
26; CHECK:       for.body25.1:
27; CHECK:    br i1 [[CMP24_1:%.*]], label %for.body25.1, label %for.inc45.1
28; CHECK:       for.inc45.1:
29; CHECK:    br label %for.body25.2
30; CHECK:       for.body25.2:
31; CHECK:    br i1 [[CMP24_2:%.*]], label %for.body25.2, label %for.inc45.2
32; CHECK:       for.inc45.2:
33; CHECK:    br label %for.body25.3
34; CHECK:       for.body25.3:
35; CHECK:    br i1 [[CMP24_3:%.*]], label %for.body25.3, label %for.inc45.3
36; CHECK:       for.inc45.3:
37; CHECK:    br i1 [[CMP21_3:%.*]], label %for.cond23.preheader, label %for.inc48
38;
39entry:
40  %A = alloca [8 x [8 x i32]], align 16
41  %B = alloca [8 x [8 x i32]], align 16
42  %C = alloca [8 x [8 x i32]], align 16
43  br label %for.cond17.preheader
44
45for.cond17.preheader:                             ; preds = %for.inc14
46  br label %for.cond20.preheader
47
48for.cond20.preheader:                             ; preds = %for.cond17.preheader, %for.inc48
49  %i.13 = phi i32 [ 0, %for.cond17.preheader ], [ %inc49, %for.inc48 ]
50  br label %for.cond23.preheader
51
52for.cond23.preheader:                             ; preds = %for.cond20.preheader, %for.inc45
53  %j.12 = phi i32 [ 0, %for.cond20.preheader ], [ %inc46, %for.inc45 ]
54  br label %for.body25
55
56for.body25:                                       ; preds = %for.cond23.preheader, %for.body25
57  %k.01 = phi i32 [ 0, %for.cond23.preheader ], [ %inc43, %for.body25 ]
58  %idxprom26 = zext i32 %i.13 to i64
59  %idxprom28 = zext i32 %j.12 to i64
60  %arrayidx29 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %C, i64 0, i64 %idxprom26, i64 %idxprom28
61  %0 = load i32, i32* %arrayidx29, align 4
62  %idxprom30 = zext i32 %i.13 to i64
63  %idxprom32 = zext i32 %k.01 to i64
64  %arrayidx33 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %A, i64 0, i64 %idxprom30, i64 %idxprom32
65  %1 = load i32, i32* %arrayidx33, align 4
66  %idxprom34 = zext i32 %k.01 to i64
67  %idxprom36 = zext i32 %j.12 to i64
68  %arrayidx37 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %B, i64 0, i64 %idxprom34, i64 %idxprom36
69  %2 = load i32, i32* %arrayidx37, align 4
70  %mul = mul nsw i32 %1, %2
71  %add = add nsw i32 %0, %mul
72  %idxprom38 = zext i32 %i.13 to i64
73  %idxprom40 = zext i32 %j.12 to i64
74  %arrayidx41 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %C, i64 0, i64 %idxprom38, i64 %idxprom40
75  store i32 %add, i32* %arrayidx41, align 4
76  %inc43 = add nuw nsw i32 %k.01, 1
77  %cmp24 = icmp ult i32 %k.01, 7
78  br i1 %cmp24, label %for.body25, label %for.inc45
79
80for.inc45:                                        ; preds = %for.body25
81  %inc46 = add nuw nsw i32 %j.12, 1
82  %cmp21 = icmp ult i32 %j.12, 7
83  br i1 %cmp21, label %for.cond23.preheader, label %for.inc48, !llvm.loop !7
84
85for.inc48:                                        ; preds = %for.inc45
86  %inc49 = add nuw nsw i32 %i.13, 1
87  %cmp18 = icmp ult i32 %i.13, 7
88  br i1 %cmp18, label %for.cond20.preheader, label %for.end50, !llvm.loop !5
89
90for.end50:                                        ; preds = %for.inc48
91  ret i32 0
92}
93
94!5 = distinct !{!5, !6}
95!6 = !{!"llvm.loop.unroll_and_jam.count", i32 4}
96!7 = distinct !{!7, !8}
97!8 = !{!"llvm.loop.unroll_and_jam.disable"}
98