xref: /llvm-project/llvm/test/Transforms/LoopDistribute/uncomputable-backedge-taken-count.ll (revision 344930316f4c901673461dcf44ad57ae6ade1015)
1; RUN: opt -passes=loop-distribute -enable-loop-distribute -verify-loop-info -verify-dom-info -S \
2; RUN:   < %s | FileCheck %s
3
4; NOTE: The tests below use infinite loops to force unknown backedge-taken counts.
5; Making the exit condition depend on a load would break current loop-distribute,
6; because it requires all accesses to end up in either of the loops, but not both.
7
8; TODO
9; Can distribute with unknown backedge-taken count, because no runtime checks are
10; required.
11define void @unknown_btc_distribute_no_checks_needed(ptr noalias %a, ptr noalias %c, ptr noalias %d) {
12; CHECK-LABEL: @unknown_btc_distribute_no_checks_needed(
13; CHECK-NEXT:  entry:
14; CHECK-NEXT:    br label %for.body
15;
16entry:
17  br label %for.body
18
19for.body:                                         ; preds = %for.body, %entry
20  %ind = phi i32 [ 0, %entry ], [ %add, %for.body ]
21
22  %arrayidxA = getelementptr inbounds i32, ptr %a, i32 %ind
23  %loadA = load i32, ptr %arrayidxA, align 4
24
25  %mulA = mul i32 %loadA, 10
26
27  %add = add nuw nsw i32 %ind, 1
28  %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i32 %add
29  store i32 %mulA, ptr %arrayidxA_plus_4, align 4
30
31  %arrayidxD = getelementptr inbounds i32, ptr %d, i32 %ind
32  %loadD = load i32, ptr %arrayidxD, align 4
33
34  %mulC = mul i32 %loadD, 20
35
36  %arrayidxC = getelementptr inbounds i32, ptr %c, i32 %ind
37  store i32 %mulC, ptr %arrayidxC, align 4
38
39  br i1 false, label %for.end, label %for.body
40
41for.end:                                          ; preds = %for.body
42  ret void
43}
44
45; Cannot distribute with unknown backedge-taken count, because runtime checks for
46; induction wrapping are required.
47define void @unknown_btc_do_not_distribute_wrapping_checks(ptr noalias %a, ptr noalias %c, ptr noalias %d) {
48; CHECK-LABEL: @unknown_btc_do_not_distribute_wrapping_checks(
49; CHECK-NEXT:  entry:
50; CHECK-NEXT:    br label %for.body
51;
52entry:
53  br label %for.body
54
55for.body:                                         ; preds = %for.body, %entry
56  %ind = phi i32 [ 0, %entry ], [ %add, %for.body ]
57
58  %arrayidxA = getelementptr inbounds i32, ptr %a, i32 %ind
59  %loadA = load i32, ptr %arrayidxA, align 4
60
61  %mulA = mul i32 %loadA, 10
62
63  %add = add i32 %ind, 1
64  %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i32 %add
65  store i32 %mulA, ptr %arrayidxA_plus_4, align 4
66
67  %arrayidxD = getelementptr inbounds i32, ptr %d, i32 %ind
68  %loadD = load i32, ptr %arrayidxD, align 4
69
70  %mulC = mul i32 %loadD, 20
71
72  %arrayidxC = getelementptr inbounds i32, ptr %c, i32 %ind
73  store i32 %mulC, ptr %arrayidxC, align 4
74
75  br i1 false, label %for.end, label %for.body
76
77for.end:                                          ; preds = %for.body
78  ret void
79}
80