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: [[TMP23:%.*]] = getelementptr i64, ptr [[SRC_1]], i64 [[TMP17]]
57 ; CHECK-NEXT: [[TMP25:%.*]] = getelementptr i64, ptr [[SRC_2]], i64 [[TMP17]]
58 ; CHECK-NEXT: [[TMP27:%.*]] = getelementptr i64, ptr [[TMP23]], i32 0
59 ; CHECK-NEXT: [[TMP28:%.*]] = call i64 @llvm.vscale.i64()
60 ; CHECK-NEXT: [[TMP29:%.*]] = mul i64 [[TMP28]], 2
61 ; CHECK-NEXT: [[TMP30:%.*]] = getelementptr i64, ptr [[TMP23]], i64 [[TMP29]]
62 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x i64>, ptr [[TMP27]], align 8
63 ; CHECK-NEXT: [[WIDE_LOAD12:%.*]] = load <vscale x 2 x i64>, ptr [[TMP30]], align 8
64 ; CHECK-NEXT: [[TMP31:%.*]] = getelementptr i64, ptr [[TMP25]], i32 0
65 ; CHECK-NEXT: [[TMP32:%.*]] = call i64 @llvm.vscale.i64()
66 ; CHECK-NEXT: [[TMP33:%.*]] = mul i64 [[TMP32]], 2
67 ; CHECK-NEXT: [[TMP34:%.*]] = getelementptr i64, ptr [[TMP25]], i64 [[TMP33]]
68 ; CHECK-NEXT: [[WIDE_LOAD13:%.*]] = load <vscale x 2 x i64>, ptr [[TMP31]], align 8
69 ; CHECK-NEXT: [[WIDE_LOAD14:%.*]] = load <vscale x 2 x i64>, ptr [[TMP34]], align 8
70 ; CHECK-NEXT: [[TMP35:%.*]] = add <vscale x 2 x i64> [[WIDE_LOAD]], [[WIDE_LOAD13]]
71 ; CHECK-NEXT: [[TMP36:%.*]] = add <vscale x 2 x i64> [[WIDE_LOAD12]], [[WIDE_LOAD14]]
72 ; CHECK-NEXT: [[TMP37:%.*]] = getelementptr i64, ptr [[DST_1]], i64 [[TMP17]]
73 ; CHECK-NEXT: [[TMP39:%.*]] = getelementptr i64, ptr [[DST_2]], i64 [[TMP17]]
74 ; CHECK-NEXT: [[TMP41:%.*]] = getelementptr i64, ptr [[TMP37]], i32 0
75 ; CHECK-NEXT: [[TMP42:%.*]] = call i64 @llvm.vscale.i64()
76 ; CHECK-NEXT: [[TMP43:%.*]] = mul i64 [[TMP42]], 2
77 ; CHECK-NEXT: [[TMP44:%.*]] = getelementptr i64, ptr [[TMP37]], i64 [[TMP43]]
78 ; CHECK-NEXT: store <vscale x 2 x i64> [[TMP35]], ptr [[TMP41]], align 8
79 ; CHECK-NEXT: store <vscale x 2 x i64> [[TMP36]], ptr [[TMP44]], align 8
80 ; CHECK-NEXT: [[TMP45:%.*]] = getelementptr i64, ptr [[TMP39]], i32 0
81 ; CHECK-NEXT: [[TMP46:%.*]] = call i64 @llvm.vscale.i64()
82 ; CHECK-NEXT: [[TMP47:%.*]] = mul i64 [[TMP46]], 2
83 ; CHECK-NEXT: [[TMP48:%.*]] = getelementptr i64, ptr [[TMP39]], i64 [[TMP47]]
84 ; CHECK-NEXT: store <vscale x 2 x i64> [[TMP35]], ptr [[TMP45]], align 8
85 ; CHECK-NEXT: store <vscale x 2 x i64> [[TMP36]], ptr [[TMP48]], align 8
86 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP50]]
87 ; CHECK-NEXT: [[TMP51:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
88 ; CHECK-NEXT: br i1 [[TMP51]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
89 ; CHECK: middle.block:
90 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[UMAX]], [[N_VEC]]
91 ; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
93 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
94 ; CHECK-NEXT: br label [[LOOP:%.*]]
96 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
97 ; CHECK-NEXT: [[GEP_SRC_1:%.*]] = getelementptr i64, ptr [[SRC_1]], i64 [[IV]]
98 ; CHECK-NEXT: [[GEP_SRC_2:%.*]] = getelementptr i64, ptr [[SRC_2]], i64 [[IV]]
99 ; CHECK-NEXT: [[L_1:%.*]] = load i64, ptr [[GEP_SRC_1]], align 8
100 ; CHECK-NEXT: [[L_2:%.*]] = load i64, ptr [[GEP_SRC_2]], align 8
101 ; CHECK-NEXT: [[ADD:%.*]] = add i64 [[L_1]], [[L_2]]
102 ; CHECK-NEXT: [[GEP_DST_1:%.*]] = getelementptr i64, ptr [[DST_1]], i64 [[IV]]
103 ; CHECK-NEXT: [[GEP_DST_2:%.*]] = getelementptr i64, ptr [[DST_2]], i64 [[IV]]
104 ; CHECK-NEXT: store i64 [[ADD]], ptr [[GEP_DST_1]], align 8
105 ; CHECK-NEXT: store i64 [[ADD]], ptr [[GEP_DST_2]], align 8
106 ; CHECK-NEXT: [[IV_NEXT]] = add nsw i64 [[IV]], 1
107 ; CHECK-NEXT: [[CMP10:%.*]] = icmp ult i64 [[IV_NEXT]], [[N]]
108 ; CHECK-NEXT: br i1 [[CMP10]], label [[LOOP]], label [[EXIT]], !llvm.loop [[LOOP3:![0-9]+]]
110 ; CHECK-NEXT: ret void
116 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
117 %gep.src.1 = getelementptr i64, ptr %src.1, i64 %iv
118 %gep.src.2 = getelementptr i64, ptr %src.2, i64 %iv
119 %l.1 = load i64, ptr %gep.src.1
120 %l.2 = load i64, ptr %gep.src.2
121 %add = add i64 %l.1, %l.2
122 %gep.dst.1 = getelementptr i64, ptr %dst.1, i64 %iv
123 %gep.dst.2 = getelementptr i64, ptr %dst.2, i64 %iv
124 store i64 %add, ptr %gep.dst.1
125 store i64 %add, ptr %gep.dst.2
126 %iv.next = add nsw i64 %iv, 1
127 %cmp10 = icmp ult i64 %iv.next, %n
128 br i1 %cmp10, label %loop, label %exit