2 ; RUN: opt < %s -basic-aa -loop-interchange -cache-line-size=64 -verify-dom-info -verify-loop-info \
3 ; RUN: -S -debug 2>&1 | FileCheck %s
5 @a = common global i32 0, align 4
6 @d = common dso_local local_unnamed_addr global [1 x [6 x i32]] zeroinitializer, align 4
8 ;; After interchanging the innermost and the middle loop, we should not continue
9 ;; doing interchange for the (new) middle loop and the outermost loop, because of
10 ;; values defined in the new innermost loop not available in the exiting block of
11 ;; the entire loop nest.
12 ; CHECK: Loops are legal to interchange
13 ; CHECK: Loops interchanged.
14 ; CHECK: Found unsupported PHI nodes in inner loop latch.
15 ; CHECK: Not interchanging loops. Cannot prove legality.
16 define void @innermost_latch_uses_values_in_middle_header() {
18 %0 = load i32, i32* @a, align 4
20 br label %outermost.header
22 outermost.header: ; preds = %outermost.latch, %entry
23 %indvar.outermost = phi i32 [ 10, %entry ], [ %indvar.outermost.next, %outermost.latch ]
24 %tobool71.i = icmp eq i32 %0, 0
25 br i1 %tobool71.i, label %middle.header, label %outermost.latch
27 middle.header: ; preds = %middle.latch, %outermost.header
28 %indvar.middle = phi i64 [ 4, %outermost.header ], [ %indvar.middle.next, %middle.latch ]
29 %indvar.middle.wide = zext i32 %b to i64 ; a def in the middle header
30 br label %innermost.header
32 innermost.header: ; preds = %middle.header, %innermost.latch
33 %indvar.innermost = phi i64 [ %indvar.innermost.next, %innermost.latch ], [ 4, %middle.header ]
34 br label %innermost.body
36 innermost.body: ; preds = %innermost.header
37 %arrayidx9.i = getelementptr inbounds [1 x [6 x i32]], [1 x [6 x i32]]* @d, i64 0, i64 %indvar.innermost, i64 %indvar.middle
38 store i32 0, i32* %arrayidx9.i, align 4
39 br label %innermost.latch
41 innermost.latch: ; preds = %innermost.body
42 %indvar.innermost.next = add nsw i64 %indvar.innermost, 1
43 %tobool5.i = icmp eq i64 %indvar.innermost.next, %indvar.middle.wide ; corresponding use in the innermost latch
44 br i1 %tobool5.i, label %middle.latch, label %innermost.header
46 middle.latch: ; preds = %innermost.latch
47 %indvar.middle.next = add nsw i64 %indvar.middle, -1
48 %tobool2.i = icmp eq i64 %indvar.middle.next, 0
49 br i1 %tobool2.i, label %outermost.latch, label %middle.header
51 outermost.latch: ; preds = %middle.latch, %outermost.header
52 %indvar.outermost.next = add nsw i32 %indvar.outermost, -5
53 %tobool.i = icmp eq i32 %indvar.outermost.next, 0
54 br i1 %tobool.i, label %outermost.exit, label %outermost.header
56 outermost.exit: ; preds = %outermost.latch