1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-vectorize -mattr=+sve -prefer-predicate-over-epilogue=scalar-epilogue -S %s | FileCheck %s
4 target triple = "aarch64-unknown-linux-gnu"
6 ; Test case where the minimum profitable trip count due to runtime checks
7 ; exceeds VF.getKnownMinValue() * UF.
8 ; FIXME: The code currently incorrectly is missing a umax(VF * UF, 28).
9 define void @min_trip_count_due_to_runtime_checks_1(ptr %dst.1, ptr %dst.2, ptr %src.1, ptr %src.2, i64 %n) {
10 ; CHECK-LABEL: @min_trip_count_due_to_runtime_checks_1(
12 ; CHECK-NEXT: [[SRC_25:%.*]] = ptrtoint ptr [[SRC_2:%.*]] to i64
13 ; CHECK-NEXT: [[SRC_13:%.*]] = ptrtoint ptr [[SRC_1:%.*]] to i64
14 ; CHECK-NEXT: [[DST_12:%.*]] = ptrtoint ptr [[DST_1:%.*]] to i64
15 ; CHECK-NEXT: [[DST_21:%.*]] = ptrtoint ptr [[DST_2:%.*]] to i64
16 ; CHECK-NEXT: [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[N:%.*]], i64 1)
17 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
18 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
19 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.umax.i64(i64 20, i64 [[TMP1]])
20 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[UMAX]], [[TMP2]]
21 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
22 ; CHECK: vector.memcheck:
23 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @llvm.vscale.i64()
24 ; CHECK-NEXT: [[TMP4:%.*]] = mul i64 [[TMP3]], 2
25 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 16
26 ; CHECK-NEXT: [[TMP6:%.*]] = sub i64 [[DST_21]], [[DST_12]]
27 ; CHECK-NEXT: [[DIFF_CHECK:%.*]] = icmp ult i64 [[TMP6]], [[TMP5]]
28 ; CHECK-NEXT: [[TMP7:%.*]] = mul i64 [[TMP4]], 16
29 ; CHECK-NEXT: [[TMP8:%.*]] = sub i64 [[DST_12]], [[SRC_13]]
30 ; CHECK-NEXT: [[DIFF_CHECK4:%.*]] = icmp ult i64 [[TMP8]], [[TMP7]]
31 ; CHECK-NEXT: [[CONFLICT_RDX:%.*]] = or i1 [[DIFF_CHECK]], [[DIFF_CHECK4]]
32 ; CHECK-NEXT: [[TMP9:%.*]] = mul i64 [[TMP4]], 16
33 ; CHECK-NEXT: [[TMP10:%.*]] = sub i64 [[DST_12]], [[SRC_25]]
34 ; CHECK-NEXT: [[DIFF_CHECK6:%.*]] = icmp ult i64 [[TMP10]], [[TMP9]]
35 ; CHECK-NEXT: [[CONFLICT_RDX7:%.*]] = or i1 [[CONFLICT_RDX]], [[DIFF_CHECK6]]
36 ; CHECK-NEXT: [[TMP11:%.*]] = mul i64 [[TMP4]], 16
37 ; CHECK-NEXT: [[TMP12:%.*]] = sub i64 [[DST_21]], [[SRC_13]]
38 ; CHECK-NEXT: [[DIFF_CHECK8:%.*]] = icmp ult i64 [[TMP12]], [[TMP11]]
39 ; CHECK-NEXT: [[CONFLICT_RDX9:%.*]] = or i1 [[CONFLICT_RDX7]], [[DIFF_CHECK8]]
40 ; CHECK-NEXT: [[TMP13:%.*]] = mul i64 [[TMP4]], 16
41 ; CHECK-NEXT: [[TMP14:%.*]] = sub i64 [[DST_21]], [[SRC_25]]
42 ; CHECK-NEXT: [[DIFF_CHECK10:%.*]] = icmp ult i64 [[TMP14]], [[TMP13]]
43 ; CHECK-NEXT: [[CONFLICT_RDX11:%.*]] = or i1 [[CONFLICT_RDX9]], [[DIFF_CHECK10]]
44 ; CHECK-NEXT: br i1 [[CONFLICT_RDX11]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
46 ; CHECK-NEXT: [[TMP15:%.*]] = call i64 @llvm.vscale.i64()
47 ; CHECK-NEXT: [[TMP16:%.*]] = mul i64 [[TMP15]], 4
48 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[UMAX]], [[TMP16]]
49 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[UMAX]], [[N_MOD_VF]]
50 ; CHECK-NEXT: [[TMP49:%.*]] = call i64 @llvm.vscale.i64()
51 ; CHECK-NEXT: [[TMP50:%.*]] = mul i64 [[TMP49]], 4
52 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
54 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
55 ; CHECK-NEXT: [[TMP17:%.*]] = add i64 [[INDEX]], 0
56 ; CHECK-NEXT: [[TMP18:%.*]] = call i64 @llvm.vscale.i64()
57 ; CHECK-NEXT: [[TMP19:%.*]] = mul i64 [[TMP18]], 2
58 ; CHECK-NEXT: [[TMP20:%.*]] = add i64 [[TMP19]], 0
59 ; CHECK-NEXT: [[TMP21:%.*]] = mul i64 [[TMP20]], 1
60 ; CHECK-NEXT: [[TMP22:%.*]] = add i64 [[INDEX]], [[TMP21]]
61 ; CHECK-NEXT: [[TMP23:%.*]] = getelementptr i64, ptr [[SRC_1]], i64 [[TMP17]]
62 ; CHECK-NEXT: [[TMP24:%.*]] = getelementptr i64, ptr [[SRC_1]], i64 [[TMP22]]
63 ; CHECK-NEXT: [[TMP25:%.*]] = getelementptr i64, ptr [[SRC_2]], i64 [[TMP17]]
64 ; CHECK-NEXT: [[TMP26:%.*]] = getelementptr i64, ptr [[SRC_2]], i64 [[TMP22]]
65 ; CHECK-NEXT: [[TMP27:%.*]] = getelementptr i64, ptr [[TMP23]], i32 0
66 ; CHECK-NEXT: [[TMP28:%.*]] = call i64 @llvm.vscale.i64()
67 ; CHECK-NEXT: [[TMP29:%.*]] = mul i64 [[TMP28]], 2
68 ; CHECK-NEXT: [[TMP30:%.*]] = getelementptr i64, ptr [[TMP23]], i64 [[TMP29]]
69 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP27]], align 8
70 ; CHECK-NEXT: [[WIDE_LOAD12:%.*]] = load <vscale x 2 x i64>, ptr [[TMP30]], align 8
71 ; CHECK-NEXT: [[TMP31:%.*]] = getelementptr i64, ptr [[TMP25]], i32 0
72 ; CHECK-NEXT: [[TMP32:%.*]] = call i64 @llvm.vscale.i64()
73 ; CHECK-NEXT: [[TMP33:%.*]] = mul i64 [[TMP32]], 2
74 ; CHECK-NEXT: [[TMP34:%.*]] = getelementptr i64, ptr [[TMP25]], i64 [[TMP33]]
75 ; CHECK-NEXT: [[WIDE_LOAD13:%.*]] = load <vscale x 2 x i64>, ptr [[TMP31]], align 8
76 ; CHECK-NEXT: [[WIDE_LOAD14:%.*]] = load <vscale x 2 x i64>, ptr [[TMP34]], align 8
77 ; CHECK-NEXT: [[TMP35:%.*]] = add <vscale x 2 x i64> [[WIDE_LOAD]], [[WIDE_LOAD13]]
78 ; CHECK-NEXT: [[TMP36:%.*]] = add <vscale x 2 x i64> [[WIDE_LOAD12]], [[WIDE_LOAD14]]
79 ; CHECK-NEXT: [[TMP37:%.*]] = getelementptr i64, ptr [[DST_1]], i64 [[TMP17]]
80 ; CHECK-NEXT: [[TMP38:%.*]] = getelementptr i64, ptr [[DST_1]], i64 [[TMP22]]
81 ; CHECK-NEXT: [[TMP39:%.*]] = getelementptr i64, ptr [[DST_2]], i64 [[TMP17]]
82 ; CHECK-NEXT: [[TMP40:%.*]] = getelementptr i64, ptr [[DST_2]], i64 [[TMP22]]
83 ; CHECK-NEXT: [[TMP41:%.*]] = getelementptr i64, ptr [[TMP37]], i32 0
84 ; CHECK-NEXT: [[TMP42:%.*]] = call i64 @llvm.vscale.i64()
85 ; CHECK-NEXT: [[TMP43:%.*]] = mul i64 [[TMP42]], 2
86 ; CHECK-NEXT: [[TMP44:%.*]] = getelementptr i64, ptr [[TMP37]], i64 [[TMP43]]
87 ; CHECK-NEXT: store <vscale x 2 x i64> [[TMP35]], ptr [[TMP41]], align 8
88 ; CHECK-NEXT: store <vscale x 2 x i64> [[TMP36]], ptr [[TMP44]], align 8
89 ; CHECK-NEXT: [[TMP45:%.*]] = getelementptr i64, ptr [[TMP39]], i32 0
90 ; CHECK-NEXT: [[TMP46:%.*]] = call i64 @llvm.vscale.i64()
91 ; CHECK-NEXT: [[TMP47:%.*]] = mul i64 [[TMP46]], 2
92 ; CHECK-NEXT: [[TMP48:%.*]] = getelementptr i64, ptr [[TMP39]], i64 [[TMP47]]
93 ; CHECK-NEXT: store <vscale x 2 x i64> [[TMP35]], ptr [[TMP45]], align 8
94 ; CHECK-NEXT: store <vscale x 2 x i64> [[TMP36]], ptr [[TMP48]], align 8
95 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP50]]
96 ; CHECK-NEXT: [[TMP51:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
97 ; CHECK-NEXT: br i1 [[TMP51]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
98 ; CHECK: middle.block:
99 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[UMAX]], [[N_VEC]]
100 ; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
102 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
103 ; CHECK-NEXT: br label [[LOOP:%.*]]
105 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
106 ; CHECK-NEXT: [[GEP_SRC_1:%.*]] = getelementptr i64, ptr [[SRC_1]], i64 [[IV]]
107 ; CHECK-NEXT: [[GEP_SRC_2:%.*]] = getelementptr i64, ptr [[SRC_2]], i64 [[IV]]
108 ; CHECK-NEXT: [[L_1:%.*]] = load i64, ptr [[GEP_SRC_1]], align 8
109 ; CHECK-NEXT: [[L_2:%.*]] = load i64, ptr [[GEP_SRC_2]], align 8
110 ; CHECK-NEXT: [[ADD:%.*]] = add i64 [[L_1]], [[L_2]]
111 ; CHECK-NEXT: [[GEP_DST_1:%.*]] = getelementptr i64, ptr [[DST_1]], i64 [[IV]]
112 ; CHECK-NEXT: [[GEP_DST_2:%.*]] = getelementptr i64, ptr [[DST_2]], i64 [[IV]]
113 ; CHECK-NEXT: store i64 [[ADD]], ptr [[GEP_DST_1]], align 8
114 ; CHECK-NEXT: store i64 [[ADD]], ptr [[GEP_DST_2]], align 8
115 ; CHECK-NEXT: [[IV_NEXT]] = add nsw i64 [[IV]], 1
116 ; CHECK-NEXT: [[CMP10:%.*]] = icmp ult i64 [[IV_NEXT]], [[N]]
117 ; CHECK-NEXT: br i1 [[CMP10]], label [[LOOP]], label [[EXIT]], !llvm.loop [[LOOP3:![0-9]+]]
119 ; CHECK-NEXT: ret void
125 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
126 %gep.src.1 = getelementptr i64, ptr %src.1, i64 %iv
127 %gep.src.2 = getelementptr i64, ptr %src.2, i64 %iv
128 %l.1 = load i64, ptr %gep.src.1
129 %l.2 = load i64, ptr %gep.src.2
130 %add = add i64 %l.1, %l.2
131 %gep.dst.1 = getelementptr i64, ptr %dst.1, i64 %iv
132 %gep.dst.2 = getelementptr i64, ptr %dst.2, i64 %iv
133 store i64 %add, ptr %gep.dst.1
134 store i64 %add, ptr %gep.dst.2
135 %iv.next = add nsw i64 %iv, 1
136 %cmp10 = icmp ult i64 %iv.next, %n
137 br i1 %cmp10, label %loop, label %exit