1 ; RUN: opt -passes=loop-distribute -enable-loop-distribute -verify-loop-info -verify-dom-info -S \
2 ; RUN: < %s | FileCheck %s
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.
9 ; Can distribute with unknown backedge-taken count, because no runtime checks are
11 define 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(
14 ; CHECK-NEXT: br label %for.body
19 for.body: ; preds = %for.body, %entry
20 %ind = phi i32 [ 0, %entry ], [ %add, %for.body ]
22 %arrayidxA = getelementptr inbounds i32, ptr %a, i32 %ind
23 %loadA = load i32, ptr %arrayidxA, align 4
25 %mulA = mul i32 %loadA, 10
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
31 %arrayidxD = getelementptr inbounds i32, ptr %d, i32 %ind
32 %loadD = load i32, ptr %arrayidxD, align 4
34 %mulC = mul i32 %loadD, 20
36 %arrayidxC = getelementptr inbounds i32, ptr %c, i32 %ind
37 store i32 %mulC, ptr %arrayidxC, align 4
39 br i1 false, label %for.end, label %for.body
41 for.end: ; preds = %for.body
45 ; Cannot distribute with unknown backedge-taken count, because runtime checks for
46 ; induction wrapping are required.
47 define 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(
50 ; CHECK-NEXT: br label %for.body
55 for.body: ; preds = %for.body, %entry
56 %ind = phi i32 [ 0, %entry ], [ %add, %for.body ]
58 %arrayidxA = getelementptr inbounds i32, ptr %a, i32 %ind
59 %loadA = load i32, ptr %arrayidxA, align 4
61 %mulA = mul i32 %loadA, 10
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
67 %arrayidxD = getelementptr inbounds i32, ptr %d, i32 %ind
68 %loadD = load i32, ptr %arrayidxD, align 4
70 %mulC = mul i32 %loadD, 20
72 %arrayidxC = getelementptr inbounds i32, ptr %c, i32 %ind
73 store i32 %mulC, ptr %arrayidxC, align 4
75 br i1 false, label %for.end, label %for.body
77 for.end: ; preds = %for.body