1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-interchange -cache-line-size=64 -S < %s | FileCheck %s
4 ; Test cases for PR43473.
6 ; In the 2 test cases below, we have a LCSSA PHI in the inner loop exit, which
7 ; is used in the outer loop latch. This is not supported.
9 define void @test1(i1 %arg) {
10 ; CHECK-LABEL: @test1(
12 ; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
13 ; CHECK: outer.header:
14 ; CHECK-NEXT: [[OUTER_IV:%.*]] = phi i64 [ undef, [[ENTRY:%.*]] ], [ [[OUTER_IV_NEXT:%.*]], [[OUTER_LATCH:%.*]] ]
15 ; CHECK-NEXT: [[IDX:%.*]] = getelementptr inbounds double, ptr undef, i64 [[OUTER_IV]]
16 ; CHECK-NEXT: br label [[INNER:%.*]]
18 ; CHECK-NEXT: [[INNER_IV:%.*]] = phi i64 [ 0, [[OUTER_HEADER]] ], [ [[INNER_IV_NEXT:%.*]], [[INNER]] ]
19 ; CHECK-NEXT: [[TMP0:%.*]] = load double, ptr [[IDX]], align 8
20 ; CHECK-NEXT: store double undef, ptr [[IDX]], align 8
21 ; CHECK-NEXT: [[INNER_IV_NEXT]] = add nuw nsw i64 [[INNER_IV]], 1
22 ; CHECK-NEXT: br i1 [[ARG:%.*]], label [[INNER]], label [[OUTER_LATCH]]
24 ; CHECK-NEXT: [[INC43_LCSSA_WIDE_US:%.*]] = phi i64 [ [[INNER_IV_NEXT]], [[INNER]] ]
25 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[INC43_LCSSA_WIDE_US]] to i32
26 ; CHECK-NEXT: [[OUTER_IV_NEXT]] = add nsw i64 [[OUTER_IV]], 1
27 ; CHECK-NEXT: br i1 [[ARG]], label [[OUTER_HEADER]], label [[OUTER_EXIT:%.*]]
29 ; CHECK-NEXT: ret void
32 br label %outer.header
34 outer.header: ; preds = %for.cond26.for.end44_crit_edge.us, %entry
35 %outer.iv = phi i64 [ undef, %entry ], [ %outer.iv.next, %outer.latch ]
36 %idx = getelementptr inbounds double, ptr undef, i64 %outer.iv
39 inner: ; preds = %for.body28.us, %for.body25.us
40 %inner.iv = phi i64 [ 0, %outer.header ], [ %inner.iv.next, %inner ]
41 %0 = load double, ptr %idx, align 8
42 store double undef, ptr %idx, align 8
43 %inner.iv.next = add nuw nsw i64 %inner.iv, 1
44 br i1 %arg, label %inner, label %outer.latch
46 outer.latch: ; preds = %inner
47 %inc43.lcssa.wide.us = phi i64 [ %inner.iv.next, %inner ]
48 %1 = trunc i64 %inc43.lcssa.wide.us to i32
49 %outer.iv.next = add nsw i64 %outer.iv, 1
50 br i1 %arg, label %outer.header, label %outer.exit
52 outer.exit: ; preds = %for.cond26.for.end44_crit_edge.us
56 ; Same as @test1, but with a dedicated inner loop exit block.
57 define void @test2(i1 %arg) {
58 ; CHECK-LABEL: @test2(
60 ; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
61 ; CHECK: outer.header:
62 ; CHECK-NEXT: [[OUTER_IV:%.*]] = phi i64 [ undef, [[ENTRY:%.*]] ], [ [[OUTER_IV_NEXT:%.*]], [[OUTER_LATCH:%.*]] ]
63 ; CHECK-NEXT: [[IDX:%.*]] = getelementptr inbounds double, ptr undef, i64 [[OUTER_IV]]
64 ; CHECK-NEXT: br label [[INNER:%.*]]
66 ; CHECK-NEXT: [[INNER_IV:%.*]] = phi i64 [ 0, [[OUTER_HEADER]] ], [ [[INNER_IV_NEXT:%.*]], [[INNER]] ]
67 ; CHECK-NEXT: [[TMP0:%.*]] = load double, ptr [[IDX]], align 8
68 ; CHECK-NEXT: store double undef, ptr [[IDX]], align 8
69 ; CHECK-NEXT: [[INNER_IV_NEXT]] = add nuw nsw i64 [[INNER_IV]], 1
70 ; CHECK-NEXT: br i1 [[ARG:%.*]], label [[INNER]], label [[INNER_EXIT:%.*]]
72 ; CHECK-NEXT: [[INC43_LCSSA_WIDE_US:%.*]] = phi i64 [ [[INNER_IV_NEXT]], [[INNER]] ]
73 ; CHECK-NEXT: br label [[OUTER_LATCH]]
75 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[INC43_LCSSA_WIDE_US]] to i32
76 ; CHECK-NEXT: [[OUTER_IV_NEXT]] = add nsw i64 [[OUTER_IV]], 1
77 ; CHECK-NEXT: br i1 [[ARG]], label [[OUTER_HEADER]], label [[OUTER_EXIT:%.*]]
79 ; CHECK-NEXT: ret void
82 br label %outer.header
84 outer.header: ; preds = %for.cond26.for.end44_crit_edge.us, %entry
85 %outer.iv = phi i64 [ undef, %entry ], [ %outer.iv.next, %outer.latch ]
86 %idx = getelementptr inbounds double, ptr undef, i64 %outer.iv
89 inner: ; preds = %for.body28.us, %for.body25.us
90 %inner.iv = phi i64 [ 0, %outer.header ], [ %inner.iv.next, %inner ]
91 %0 = load double, ptr %idx, align 8
92 store double undef, ptr %idx, align 8
93 %inner.iv.next = add nuw nsw i64 %inner.iv, 1
94 br i1 %arg, label %inner, label %inner.exit
97 %inc43.lcssa.wide.us = phi i64 [ %inner.iv.next, %inner ]
100 outer.latch: ; preds = %inner
101 %1 = trunc i64 %inc43.lcssa.wide.us to i32
102 %outer.iv.next = add nsw i64 %outer.iv, 1
103 br i1 %arg, label %outer.header, label %outer.exit
105 outer.exit: ; preds = %for.cond26.for.end44_crit_edge.us