1 ; RUN: opt -passes=loop-distribute -enable-loop-distribute -verify-loop-info -verify-dom-info -S \
2 ; RUN: < %s | FileCheck %s
4 target datalayout = "e-m:o-i32:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-apple-macosx10.10.0"
7 ; NOTE: The tests below use infinite loops to force unknown backedge-taken counts.
8 ; Making the exit condition depend on a load would break current loop-distribute,
9 ; because it requires all accesses to end up in either of the loops, but not both.
12 ; Can distribute with unknown backedge-taken count, because no runtime checks are
14 define void @unknown_btc_distribute_no_checks_needed(ptr noalias %a,
17 ; CHECK-LABEL: @unknown_btc_distribute_no_checks_needed(
19 ; CHECK-NEXT: br label %for.body
24 for.body: ; preds = %for.body, %entry
25 %ind = phi i32 [ 0, %entry ], [ %add, %for.body ]
27 %arrayidxA = getelementptr inbounds i32, ptr %a, i32 %ind
28 %loadA = load i32, ptr %arrayidxA, align 4
30 %mulA = mul i32 %loadA, 10
32 %add = add nuw nsw i32 %ind, 1
33 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i32 %add
34 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
36 %arrayidxD = getelementptr inbounds i32, ptr %d, i32 %ind
37 %loadD = load i32, ptr %arrayidxD, align 4
39 %mulC = mul i32 %loadD, 20
41 %arrayidxC = getelementptr inbounds i32, ptr %c, i32 %ind
42 store i32 %mulC, ptr %arrayidxC, align 4
44 br i1 false, label %for.end, label %for.body
46 for.end: ; preds = %for.body
50 ; Cannot distribute with unknown backedge-taken count, because runtime checks for
51 ; induction wrapping are required.
52 define void @unknown_btc_do_not_distribute_wrapping_checks(ptr noalias %a,
55 ; CHECK-LABEL: @unknown_btc_do_not_distribute_wrapping_checks(
57 ; CHECK-NEXT: br label %for.body
62 for.body: ; preds = %for.body, %entry
63 %ind = phi i32 [ 0, %entry ], [ %add, %for.body ]
65 %arrayidxA = getelementptr inbounds i32, ptr %a, i32 %ind
66 %loadA = load i32, ptr %arrayidxA, align 4
68 %mulA = mul i32 %loadA, 10
70 %add = add i32 %ind, 1
71 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i32 %add
72 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
74 %arrayidxD = getelementptr inbounds i32, ptr %d, i32 %ind
75 %loadD = load i32, ptr %arrayidxD, align 4
77 %mulC = mul i32 %loadD, 20
79 %arrayidxC = getelementptr inbounds i32, ptr %c, i32 %ind
80 store i32 %mulC, ptr %arrayidxC, align 4
82 br i1 false, label %for.end, label %for.body
84 for.end: ; preds = %for.body