1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt -passes=loop-versioning -S < %s | FileCheck %s
4 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
6 ; Version this loop with overlap checks between a, c and b, c.
8 define void @f(ptr %a, ptr %b, ptr %c) {
9 ; CHECK-LABEL: define void @f
10 ; CHECK-SAME: (ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]]) {
11 ; CHECK-NEXT: for.body.lver.check:
12 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[C]], i64 80
13 ; CHECK-NEXT: [[SCEVGEP1:%.*]] = getelementptr i8, ptr [[A]], i64 80
14 ; CHECK-NEXT: [[SCEVGEP2:%.*]] = getelementptr i8, ptr [[B]], i64 80
15 ; CHECK-NEXT: [[BOUND0:%.*]] = icmp ult ptr [[C]], [[SCEVGEP1]]
16 ; CHECK-NEXT: [[BOUND1:%.*]] = icmp ult ptr [[A]], [[SCEVGEP]]
17 ; CHECK-NEXT: [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
18 ; CHECK-NEXT: [[BOUND03:%.*]] = icmp ult ptr [[C]], [[SCEVGEP2]]
19 ; CHECK-NEXT: [[BOUND14:%.*]] = icmp ult ptr [[B]], [[SCEVGEP]]
20 ; CHECK-NEXT: [[FOUND_CONFLICT5:%.*]] = and i1 [[BOUND03]], [[BOUND14]]
21 ; CHECK-NEXT: [[CONFLICT_RDX:%.*]] = or i1 [[FOUND_CONFLICT]], [[FOUND_CONFLICT5]]
22 ; CHECK-NEXT: br i1 [[CONFLICT_RDX]], label [[FOR_BODY_PH_LVER_ORIG:%.*]], label [[FOR_BODY_PH:%.*]]
23 ; CHECK: for.body.ph.lver.orig:
24 ; CHECK-NEXT: br label [[FOR_BODY_LVER_ORIG:%.*]]
25 ; CHECK: for.body.lver.orig:
26 ; CHECK-NEXT: [[IND_LVER_ORIG:%.*]] = phi i64 [ 0, [[FOR_BODY_PH_LVER_ORIG]] ], [ [[ADD_LVER_ORIG:%.*]], [[FOR_BODY_LVER_ORIG]] ]
27 ; CHECK-NEXT: [[ARRAYIDXA_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[IND_LVER_ORIG]]
28 ; CHECK-NEXT: [[LOADA_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDXA_LVER_ORIG]], align 4
29 ; CHECK-NEXT: [[ARRAYIDXB_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[IND_LVER_ORIG]]
30 ; CHECK-NEXT: [[LOADB_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDXB_LVER_ORIG]], align 4
31 ; CHECK-NEXT: [[MULC_LVER_ORIG:%.*]] = mul i32 [[LOADA_LVER_ORIG]], [[LOADB_LVER_ORIG]]
32 ; CHECK-NEXT: [[ARRAYIDXC_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[C]], i64 [[IND_LVER_ORIG]]
33 ; CHECK-NEXT: store i32 [[MULC_LVER_ORIG]], ptr [[ARRAYIDXC_LVER_ORIG]], align 4
34 ; CHECK-NEXT: [[ADD_LVER_ORIG]] = add nuw nsw i64 [[IND_LVER_ORIG]], 1
35 ; CHECK-NEXT: [[EXITCOND_LVER_ORIG:%.*]] = icmp eq i64 [[ADD_LVER_ORIG]], 20
36 ; CHECK-NEXT: br i1 [[EXITCOND_LVER_ORIG]], label [[FOR_END_LOOPEXIT:%.*]], label [[FOR_BODY_LVER_ORIG]]
38 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
40 ; CHECK-NEXT: [[IND:%.*]] = phi i64 [ 0, [[FOR_BODY_PH]] ], [ [[ADD:%.*]], [[FOR_BODY]] ]
41 ; CHECK-NEXT: [[ARRAYIDXA:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[IND]]
42 ; CHECK-NEXT: [[LOADA:%.*]] = load i32, ptr [[ARRAYIDXA]], align 4, !alias.scope !0
43 ; CHECK-NEXT: [[ARRAYIDXB:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[IND]]
44 ; CHECK-NEXT: [[LOADB:%.*]] = load i32, ptr [[ARRAYIDXB]], align 4, !alias.scope !3
45 ; CHECK-NEXT: [[MULC:%.*]] = mul i32 [[LOADA]], [[LOADB]]
46 ; CHECK-NEXT: [[ARRAYIDXC:%.*]] = getelementptr inbounds i32, ptr [[C]], i64 [[IND]]
47 ; CHECK-NEXT: store i32 [[MULC]], ptr [[ARRAYIDXC]], align 4, !alias.scope !5, !noalias !7
48 ; CHECK-NEXT: [[ADD]] = add nuw nsw i64 [[IND]], 1
49 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[ADD]], 20
50 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_END_LOOPEXIT6:%.*]], label [[FOR_BODY]]
51 ; CHECK: for.end.loopexit:
52 ; CHECK-NEXT: br label [[FOR_END:%.*]]
53 ; CHECK: for.end.loopexit6:
54 ; CHECK-NEXT: br label [[FOR_END]]
56 ; CHECK-NEXT: ret void
63 for.body: ; preds = %for.body, %entry
64 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
66 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
67 %loadA = load i32, ptr %arrayidxA, align 4
69 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
70 %loadB = load i32, ptr %arrayidxB, align 4
72 %mulC = mul i32 %loadA, %loadB
74 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
75 store i32 %mulC, ptr %arrayidxC, align 4
77 %add = add nuw nsw i64 %ind, 1
78 %exitcond = icmp eq i64 %add, 20
79 br i1 %exitcond, label %for.end, label %for.body
81 for.end: ; preds = %for.body