1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-vectorize,dce -prefer-predicate-over-epilogue=scalar-epilogue \
3 ; RUN: -enable-epilogue-vectorization=false < %s -S | FileCheck %s
5 target triple = "aarch64-unknown-linux-gnu"
7 ; This should be vscale x 8 vectorized, maybe with some interleaving.
9 define void @fneg(ptr nocapture noundef writeonly %d, ptr nocapture noundef readonly %s, i32 noundef %n) #0 {
12 ; CHECK-NEXT: [[S2:%.*]] = ptrtoint ptr [[S:%.*]] to i64
13 ; CHECK-NEXT: [[D1:%.*]] = ptrtoint ptr [[D:%.*]] to i64
14 ; CHECK-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[N:%.*]], 0
15 ; CHECK-NEXT: br i1 [[CMP6]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
16 ; CHECK: for.body.preheader:
17 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[N]] to i64
18 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
19 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 16
20 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[WIDE_TRIP_COUNT]], [[TMP1]]
21 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
22 ; CHECK: vector.memcheck:
23 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
24 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 8
25 ; CHECK-NEXT: [[TMP4:%.*]] = mul i64 [[TMP3]], 4
26 ; CHECK-NEXT: [[TMP5:%.*]] = sub i64 [[D1]], [[S2]]
27 ; CHECK-NEXT: [[DIFF_CHECK:%.*]] = icmp ult i64 [[TMP5]], [[TMP4]]
28 ; CHECK-NEXT: br i1 [[DIFF_CHECK]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
30 ; CHECK-NEXT: [[TMP6:%.*]] = call i64 @llvm.vscale.i64()
31 ; CHECK-NEXT: [[TMP7:%.*]] = mul i64 [[TMP6]], 16
32 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[WIDE_TRIP_COUNT]], [[TMP7]]
33 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[WIDE_TRIP_COUNT]], [[N_MOD_VF]]
34 ; CHECK-NEXT: [[TMP8:%.*]] = call i64 @llvm.vscale.i64()
35 ; CHECK-NEXT: [[TMP9:%.*]] = mul i64 [[TMP8]], 16
36 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
38 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
39 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX]], 0
40 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr inbounds half, ptr [[S]], i64 [[TMP10]]
41 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr inbounds half, ptr [[TMP11]], i32 0
42 ; CHECK-NEXT: [[TMP13:%.*]] = call i64 @llvm.vscale.i64()
43 ; CHECK-NEXT: [[TMP14:%.*]] = mul i64 [[TMP13]], 8
44 ; CHECK-NEXT: [[TMP15:%.*]] = getelementptr inbounds half, ptr [[TMP11]], i64 [[TMP14]]
45 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 8 x half>, ptr [[TMP12]], align 2
46 ; CHECK-NEXT: [[WIDE_LOAD3:%.*]] = load <vscale x 8 x half>, ptr [[TMP15]], align 2
47 ; CHECK-NEXT: [[TMP16:%.*]] = fneg <vscale x 8 x half> [[WIDE_LOAD]]
48 ; CHECK-NEXT: [[TMP17:%.*]] = fneg <vscale x 8 x half> [[WIDE_LOAD3]]
49 ; CHECK-NEXT: [[TMP18:%.*]] = getelementptr inbounds half, ptr [[D]], i64 [[TMP10]]
50 ; CHECK-NEXT: [[TMP19:%.*]] = getelementptr inbounds half, ptr [[TMP18]], i32 0
51 ; CHECK-NEXT: [[TMP20:%.*]] = call i64 @llvm.vscale.i64()
52 ; CHECK-NEXT: [[TMP21:%.*]] = mul i64 [[TMP20]], 8
53 ; CHECK-NEXT: [[TMP22:%.*]] = getelementptr inbounds half, ptr [[TMP18]], i64 [[TMP21]]
54 ; CHECK-NEXT: store <vscale x 8 x half> [[TMP16]], ptr [[TMP19]], align 2
55 ; CHECK-NEXT: store <vscale x 8 x half> [[TMP17]], ptr [[TMP22]], align 2
56 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP9]]
57 ; CHECK-NEXT: [[TMP23:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
58 ; CHECK-NEXT: br i1 [[TMP23]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
59 ; CHECK: middle.block:
60 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[WIDE_TRIP_COUNT]], [[N_VEC]]
61 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[SCALAR_PH]]
63 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER]] ], [ 0, [[VECTOR_MEMCHECK]] ]
64 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
65 ; CHECK: for.cond.cleanup.loopexit:
66 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
67 ; CHECK: for.cond.cleanup:
68 ; CHECK-NEXT: ret void
70 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
71 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds half, ptr [[S]], i64 [[INDVARS_IV]]
72 ; CHECK-NEXT: [[TMP24:%.*]] = load half, ptr [[ARRAYIDX]], align 2
73 ; CHECK-NEXT: [[FNEG:%.*]] = fneg half [[TMP24]]
74 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds half, ptr [[D]], i64 [[INDVARS_IV]]
75 ; CHECK-NEXT: store half [[FNEG]], ptr [[ARRAYIDX2]], align 2
76 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
77 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
78 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
81 %cmp6 = icmp sgt i32 %n, 0
82 br i1 %cmp6, label %for.body.preheader, label %for.cond.cleanup
84 for.body.preheader: ; preds = %entry
85 %wide.trip.count = zext i32 %n to i64
88 for.cond.cleanup: ; preds = %for.body, %entry
91 for.body: ; preds = %for.body.preheader, %for.body
92 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
93 %arrayidx = getelementptr inbounds half, ptr %s, i64 %indvars.iv
94 %0 = load half, ptr %arrayidx, align 2
96 %arrayidx2 = getelementptr inbounds half, ptr %d, i64 %indvars.iv
97 store half %fneg, ptr %arrayidx2, align 2
98 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
99 %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
100 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
103 attributes #0 = { "target-features"="+sve" vscale_range(1,16) }