1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt -passes=loop-distribute -enable-loop-distribute -verify-loop-info -verify-dom-info -S < %s \
5 ; We should distribute this loop along === but not along ---. The last
6 ; partition won't be vectorized due to conditional stores so it's better to
7 ; keep it with the second partition which has a dependence cycle.
10 ; for (i = 0; i < n; i++) {
12 ;=============================
13 ; A[i + 1] = A[i] * B[i];
14 ;-----------------------------
19 ; Ensure that we have only two partitions, the first with one multiplication
20 ; and the second with two.
21 define void @f(ptr noalias %a, ptr noalias %b, ptr noalias %c, ptr noalias %d, ptr noalias %e, ptr noalias %g, ptr noalias %h, ptr noalias %j, i64 %x) {
22 ; CHECK-LABEL: define void @f(
23 ; CHECK-SAME: ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias [[C:%.*]], ptr noalias [[D:%.*]], ptr noalias [[E:%.*]], ptr noalias [[G:%.*]], ptr noalias [[H:%.*]], ptr noalias [[J:%.*]], i64 [[X:%.*]]) {
24 ; CHECK-NEXT: [[ENTRY:.*:]]
25 ; CHECK-NEXT: br label %[[ENTRY_SPLIT_LDIST1:.*]]
26 ; CHECK: [[ENTRY_SPLIT_LDIST1]]:
27 ; CHECK-NEXT: br label %[[FOR_BODY_LDIST1:.*]]
28 ; CHECK: [[FOR_BODY_LDIST1]]:
29 ; CHECK-NEXT: [[IND_LDIST1:%.*]] = phi i64 [ 0, %[[ENTRY_SPLIT_LDIST1]] ], [ [[ADD_LDIST1:%.*]], %[[IF_END_LDIST1:.*]] ]
30 ; CHECK-NEXT: [[ARRAYIDXD_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[D]], i64 [[IND_LDIST1]]
31 ; CHECK-NEXT: [[LOADD_LDIST1:%.*]] = load i32, ptr [[ARRAYIDXD_LDIST1]], align 4
32 ; CHECK-NEXT: [[ARRAYIDXE_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[E]], i64 [[IND_LDIST1]]
33 ; CHECK-NEXT: [[LOADE_LDIST1:%.*]] = load i32, ptr [[ARRAYIDXE_LDIST1]], align 4
34 ; CHECK-NEXT: [[MULC_LDIST1:%.*]] = mul i32 [[LOADD_LDIST1]], [[LOADE_LDIST1]]
35 ; CHECK-NEXT: [[ARRAYIDXC_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[C]], i64 [[IND_LDIST1]]
36 ; CHECK-NEXT: store i32 [[MULC_LDIST1]], ptr [[ARRAYIDXC_LDIST1]], align 4
37 ; CHECK-NEXT: [[ADD_LDIST1]] = add nuw nsw i64 [[IND_LDIST1]], 1
38 ; CHECK-NEXT: [[IF_COND_LDIST1:%.*]] = icmp eq i64 [[IND_LDIST1]], [[X]]
39 ; CHECK-NEXT: br i1 [[IF_COND_LDIST1]], label %[[IF_THEN_LDIST1:.*]], label %[[IF_END_LDIST1]]
40 ; CHECK: [[IF_THEN_LDIST1]]:
41 ; CHECK-NEXT: br label %[[IF_END_LDIST1]]
42 ; CHECK: [[IF_END_LDIST1]]:
43 ; CHECK-NEXT: [[EXITCOND_LDIST1:%.*]] = icmp eq i64 [[ADD_LDIST1]], 20
44 ; CHECK-NEXT: br i1 [[EXITCOND_LDIST1]], label %[[ENTRY_SPLIT:.*]], label %[[FOR_BODY_LDIST1]]
45 ; CHECK: [[ENTRY_SPLIT]]:
46 ; CHECK-NEXT: br label %[[FOR_BODY:.*]]
47 ; CHECK: [[FOR_BODY]]:
48 ; CHECK-NEXT: [[IND:%.*]] = phi i64 [ 0, %[[ENTRY_SPLIT]] ], [ [[ADD:%.*]], %[[IF_END:.*]] ]
49 ; CHECK-NEXT: [[ARRAYIDXA:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[IND]]
50 ; CHECK-NEXT: [[LOADA:%.*]] = load i32, ptr [[ARRAYIDXA]], align 4
51 ; CHECK-NEXT: [[ARRAYIDXB:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[IND]]
52 ; CHECK-NEXT: [[LOADB:%.*]] = load i32, ptr [[ARRAYIDXB]], align 4
53 ; CHECK-NEXT: [[MULA:%.*]] = mul i32 [[LOADB]], [[LOADA]]
54 ; CHECK-NEXT: [[ADD]] = add nuw nsw i64 [[IND]], 1
55 ; CHECK-NEXT: [[ARRAYIDXA_PLUS_4:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[ADD]]
56 ; CHECK-NEXT: store i32 [[MULA]], ptr [[ARRAYIDXA_PLUS_4]], align 4
57 ; CHECK-NEXT: [[IF_COND:%.*]] = icmp eq i64 [[IND]], [[X]]
58 ; CHECK-NEXT: br i1 [[IF_COND]], label %[[IF_THEN:.*]], label %[[IF_END]]
60 ; CHECK-NEXT: [[ARRAYIDXH:%.*]] = getelementptr inbounds i32, ptr [[H]], i64 [[IND]]
61 ; CHECK-NEXT: [[LOADH:%.*]] = load i32, ptr [[ARRAYIDXH]], align 4
62 ; CHECK-NEXT: [[ARRAYIDXJ:%.*]] = getelementptr inbounds i32, ptr [[J]], i64 [[IND]]
63 ; CHECK-NEXT: [[LOADJ:%.*]] = load i32, ptr [[ARRAYIDXJ]], align 4
64 ; CHECK-NEXT: [[MULG:%.*]] = mul i32 [[LOADH]], [[LOADJ]]
65 ; CHECK-NEXT: [[ARRAYIDXG:%.*]] = getelementptr inbounds i32, ptr [[G]], i64 [[IND]]
66 ; CHECK-NEXT: store i32 [[MULG]], ptr [[ARRAYIDXG]], align 4
67 ; CHECK-NEXT: br label %[[IF_END]]
69 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[ADD]], 20
70 ; CHECK-NEXT: br i1 [[EXITCOND]], label %[[FOR_END:.*]], label %[[FOR_BODY]]
72 ; CHECK-NEXT: ret void
77 for.body: ; preds = %for.body, %entry
78 %ind = phi i64 [ 0, %entry ], [ %add, %if.end ]
80 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind
81 %loadD = load i32, ptr %arrayidxD, align 4
83 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind
84 %loadE = load i32, ptr %arrayidxE, align 4
86 %mulC = mul i32 %loadD, %loadE
88 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
89 store i32 %mulC, ptr %arrayidxC, align 4
92 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
93 %loadA = load i32, ptr %arrayidxA, align 4
95 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
96 %loadB = load i32, ptr %arrayidxB, align 4
98 %mulA = mul i32 %loadB, %loadA
100 %add = add nuw nsw i64 %ind, 1
101 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
102 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
104 %if.cond = icmp eq i64 %ind, %x
105 br i1 %if.cond, label %if.then, label %if.end
108 %arrayidxH = getelementptr inbounds i32, ptr %h, i64 %ind
109 %loadH = load i32, ptr %arrayidxH, align 4
111 %arrayidxJ = getelementptr inbounds i32, ptr %j, i64 %ind
112 %loadJ = load i32, ptr %arrayidxJ, align 4
114 %mulG = mul i32 %loadH, %loadJ
116 %arrayidxG = getelementptr inbounds i32, ptr %g, i64 %ind
117 store i32 %mulG, ptr %arrayidxG, align 4
121 %exitcond = icmp eq i64 %add, 20
122 br i1 %exitcond, label %for.end, label %for.body
124 for.end: ; preds = %for.body