1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-distribute -enable-loop-distribute \
3 ; RUN: -verify-loop-info -verify-dom-info -S < %s | FileCheck %s
5 ; Derived from crash-in-memcheck-generation.ll
7 ; Make sure the loop is distributed even with a convergent
8 ; op. LoopAccessAnalysis says that runtime checks are necessary, but
9 ; none are cross partition, so none are truly needed.
11 define void @f(ptr %a, ptr %b, ptr noalias %c, ptr noalias %d, ptr noalias %e) #1 {
14 ; CHECK-NEXT: br label [[ENTRY_SPLIT_LDIST1:%.*]]
15 ; CHECK: entry.split.ldist1:
16 ; CHECK-NEXT: br label [[FOR_BODY_LDIST1:%.*]]
17 ; CHECK: for.body.ldist1:
18 ; CHECK-NEXT: [[IND_LDIST1:%.*]] = phi i64 [ 0, [[ENTRY_SPLIT_LDIST1]] ], [ [[ADD_LDIST1:%.*]], [[FOR_BODY_LDIST1]] ]
19 ; CHECK-NEXT: [[ARRAYIDXA_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[IND_LDIST1]]
20 ; CHECK-NEXT: [[LOADA_LDIST1:%.*]] = load i32, ptr [[ARRAYIDXA_LDIST1]], align 4
21 ; CHECK-NEXT: [[ARRAYIDXB_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[B:%.*]], i64 [[IND_LDIST1]]
22 ; CHECK-NEXT: [[LOADB_LDIST1:%.*]] = load i32, ptr [[ARRAYIDXB_LDIST1]], align 4
23 ; CHECK-NEXT: [[MULA_LDIST1:%.*]] = mul i32 [[LOADB_LDIST1]], [[LOADA_LDIST1]]
24 ; CHECK-NEXT: [[ADD_LDIST1]] = add nuw nsw i64 [[IND_LDIST1]], 1
25 ; CHECK-NEXT: [[ARRAYIDXA_PLUS_4_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[ADD_LDIST1]]
26 ; CHECK-NEXT: store i32 [[MULA_LDIST1]], ptr [[ARRAYIDXA_PLUS_4_LDIST1]], align 4
27 ; CHECK-NEXT: [[EXITCOND_LDIST1:%.*]] = icmp eq i64 [[ADD_LDIST1]], 20
28 ; CHECK-NEXT: br i1 [[EXITCOND_LDIST1]], label [[ENTRY_SPLIT:%.*]], label [[FOR_BODY_LDIST1]]
30 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
32 ; CHECK-NEXT: [[IND:%.*]] = phi i64 [ 0, [[ENTRY_SPLIT]] ], [ [[ADD:%.*]], [[FOR_BODY]] ]
33 ; CHECK-NEXT: [[ADD]] = add nuw nsw i64 [[IND]], 1
34 ; CHECK-NEXT: [[ARRAYIDXD:%.*]] = getelementptr inbounds i32, ptr [[D:%.*]], i64 [[IND]]
35 ; CHECK-NEXT: [[LOADD:%.*]] = load i32, ptr [[ARRAYIDXD]], align 4
36 ; CHECK-NEXT: [[CONVERGENTD:%.*]] = call i32 @llvm.convergent(i32 [[LOADD]])
37 ; CHECK-NEXT: [[ARRAYIDXE:%.*]] = getelementptr inbounds i32, ptr [[E:%.*]], i64 [[IND]]
38 ; CHECK-NEXT: [[LOADE:%.*]] = load i32, ptr [[ARRAYIDXE]], align 4
39 ; CHECK-NEXT: [[MULC:%.*]] = mul i32 [[CONVERGENTD]], [[LOADE]]
40 ; CHECK-NEXT: [[ARRAYIDXC:%.*]] = getelementptr inbounds i32, ptr [[C:%.*]], i64 [[IND]]
41 ; CHECK-NEXT: store i32 [[MULC]], ptr [[ARRAYIDXC]], align 4
42 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[ADD]], 20
43 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
45 ; CHECK-NEXT: ret void
50 for.body: ; preds = %for.body, %entry
51 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
53 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
54 %loadA = load i32, ptr %arrayidxA, align 4
56 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
57 %loadB = load i32, ptr %arrayidxB, align 4
59 %mulA = mul i32 %loadB, %loadA
61 %add = add nuw nsw i64 %ind, 1
62 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
63 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
65 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind
66 %loadD = load i32, ptr %arrayidxD, align 4
67 %convergentD = call i32 @llvm.convergent(i32 %loadD)
69 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind
70 %loadE = load i32, ptr %arrayidxE, align 4
72 %mulC = mul i32 %convergentD, %loadE
74 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
75 store i32 %mulC, ptr %arrayidxC, align 4
77 %exitcond = icmp eq i64 %add, 20
78 br i1 %exitcond, label %for.end, label %for.body
80 for.end: ; preds = %for.body
84 declare i32 @llvm.convergent(i32) #0
86 attributes #0 = { nounwind readnone convergent }
87 attributes #1 = { nounwind convergent }