1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt -S -mtriple aarch64 -mattr=+sve -passes=loop-vectorize -enable-vplan-native-path < %s | FileCheck %s
4 @A = external local_unnamed_addr global [1024 x float], align 4
5 @B = external local_unnamed_addr global [512 x float], align 4
7 ; Test if the vplan-native-path successfully vectorizes a loop using scalable vectors if the target preferes scalable vectors.
9 ; CHECK-LABEL: define void @foo
10 ; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
12 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
13 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
14 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 1024, [[TMP1]]
15 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
17 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
18 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
19 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 1024, [[TMP3]]
20 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 1024, [[N_MOD_VF]]
21 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
22 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 4
23 ; CHECK-NEXT: [[TMP6:%.*]] = call <vscale x 4 x i64> @llvm.stepvector.nxv4i64()
24 ; CHECK-NEXT: [[TMP7:%.*]] = add <vscale x 4 x i64> [[TMP6]], zeroinitializer
25 ; CHECK-NEXT: [[TMP8:%.*]] = mul <vscale x 4 x i64> [[TMP7]], splat (i64 1)
26 ; CHECK-NEXT: [[INDUCTION:%.*]] = add <vscale x 4 x i64> zeroinitializer, [[TMP8]]
27 ; CHECK-NEXT: [[TMP9:%.*]] = mul i64 1, [[TMP5]]
28 ; CHECK-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[TMP9]], i64 0
29 ; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <vscale x 4 x i64> [[DOTSPLATINSERT]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
30 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
32 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_LATCH:%.*]] ]
33 ; CHECK-NEXT: [[VEC_IND:%.*]] = phi <vscale x 4 x i64> [ [[INDUCTION]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_LATCH]] ]
34 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds [1024 x float], ptr @A, i64 0, <vscale x 4 x i64> [[VEC_IND]]
35 ; CHECK-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 4 x float> @llvm.masked.gather.nxv4f32.nxv4p0(<vscale x 4 x ptr> [[TMP10]], i32 4, <vscale x 4 x i1> splat (i1 true), <vscale x 4 x float> poison)
36 ; CHECK-NEXT: br label [[INNER_LOOP1:%.*]]
38 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <vscale x 4 x i64> [ zeroinitializer, [[VECTOR_BODY]] ], [ [[TMP13:%.*]], [[INNER_LOOP1]] ]
39 ; CHECK-NEXT: [[VEC_PHI2:%.*]] = phi <vscale x 4 x float> [ [[WIDE_MASKED_GATHER]], [[VECTOR_BODY]] ], [ [[TMP12:%.*]], [[INNER_LOOP1]] ]
40 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr inbounds [512 x float], ptr @B, i64 0, <vscale x 4 x i64> [[VEC_PHI]]
41 ; CHECK-NEXT: [[WIDE_MASKED_GATHER3:%.*]] = call <vscale x 4 x float> @llvm.masked.gather.nxv4f32.nxv4p0(<vscale x 4 x ptr> [[TMP11]], i32 4, <vscale x 4 x i1> splat (i1 true), <vscale x 4 x float> poison)
42 ; CHECK-NEXT: [[TMP12]] = fmul <vscale x 4 x float> [[VEC_PHI2]], [[WIDE_MASKED_GATHER3]]
43 ; CHECK-NEXT: [[TMP13]] = add nuw nsw <vscale x 4 x i64> [[VEC_PHI]], splat (i64 1)
44 ; CHECK-NEXT: [[TMP14:%.*]] = icmp eq <vscale x 4 x i64> [[TMP13]], splat (i64 512)
45 ; CHECK-NEXT: [[TMP15:%.*]] = extractelement <vscale x 4 x i1> [[TMP14]], i32 0
46 ; CHECK-NEXT: br i1 [[TMP15]], label [[VECTOR_LATCH]], label [[INNER_LOOP1]]
47 ; CHECK: vector.latch:
48 ; CHECK-NEXT: [[VEC_PHI4:%.*]] = phi <vscale x 4 x float> [ [[TMP12]], [[INNER_LOOP1]] ]
49 ; CHECK-NEXT: call void @llvm.masked.scatter.nxv4f32.nxv4p0(<vscale x 4 x float> [[VEC_PHI4]], <vscale x 4 x ptr> [[TMP10]], i32 4, <vscale x 4 x i1> splat (i1 true))
50 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
51 ; CHECK-NEXT: [[VEC_IND_NEXT]] = add <vscale x 4 x i64> [[VEC_IND]], [[DOTSPLAT]]
52 ; CHECK-NEXT: [[TMP16:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
53 ; CHECK-NEXT: br i1 [[TMP16]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
54 ; CHECK: middle.block:
55 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 1024, [[N_VEC]]
56 ; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
58 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
59 ; CHECK-NEXT: br label [[OUTER_LOOP:%.*]]
61 ; CHECK-NEXT: [[I:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[OUTER_LOOP_LATCH:%.*]] ]
62 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 [[I]]
63 ; CHECK-NEXT: [[X_START:%.*]] = load float, ptr [[ARRAYIDX1]], align 4
64 ; CHECK-NEXT: br label [[INNER_LOOP:%.*]]
66 ; CHECK-NEXT: [[J:%.*]] = phi i64 [ 0, [[OUTER_LOOP]] ], [ [[J_NEXT:%.*]], [[INNER_LOOP]] ]
67 ; CHECK-NEXT: [[X:%.*]] = phi float [ [[X_START]], [[OUTER_LOOP]] ], [ [[X_NEXT:%.*]], [[INNER_LOOP]] ]
68 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds [512 x float], ptr @B, i64 0, i64 [[J]]
69 ; CHECK-NEXT: [[B:%.*]] = load float, ptr [[ARRAYIDX2]], align 4
70 ; CHECK-NEXT: [[X_NEXT]] = fmul float [[X]], [[B]]
71 ; CHECK-NEXT: [[J_NEXT]] = add nuw nsw i64 [[J]], 1
72 ; CHECK-NEXT: [[INNER_EXITCOND:%.*]] = icmp eq i64 [[J_NEXT]], 512
73 ; CHECK-NEXT: br i1 [[INNER_EXITCOND]], label [[OUTER_LOOP_LATCH]], label [[INNER_LOOP]]
74 ; CHECK: outer_loop_latch:
75 ; CHECK-NEXT: [[X_NEXT_LCSSA:%.*]] = phi float [ [[X_NEXT]], [[INNER_LOOP]] ]
76 ; CHECK-NEXT: store float [[X_NEXT_LCSSA]], ptr [[ARRAYIDX1]], align 4
77 ; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i64 [[I]], 1
78 ; CHECK-NEXT: [[OUTER_EXITCOND:%.*]] = icmp eq i64 [[I_NEXT]], 1024
79 ; CHECK-NEXT: br i1 [[OUTER_EXITCOND]], label [[EXIT]], label [[OUTER_LOOP]], !llvm.loop [[LOOP3:![0-9]+]]
81 ; CHECK-NEXT: ret void
87 %i = phi i64 [ 0, %entry ], [ %i.next, %outer_loop_latch ]
88 %arrayidx1 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %i
89 %x.start = load float, ptr %arrayidx1, align 4
93 %j = phi i64 [ 0, %outer_loop ], [ %j.next, %inner_loop ]
94 %x = phi float [ %x.start, %outer_loop ], [ %x.next, %inner_loop ]
95 %arrayidx2 = getelementptr inbounds [512 x float], ptr @B, i64 0, i64 %j
96 %b = load float, ptr %arrayidx2, align 4
97 %x.next = fmul float %x, %b
98 %j.next = add nuw nsw i64 %j, 1
99 %inner_exitcond = icmp eq i64 %j.next, 512
100 br i1 %inner_exitcond, label %outer_loop_latch, label %inner_loop
103 store float %x.next, ptr %arrayidx1, align 4
104 %i.next = add nuw nsw i64 %i, 1
105 %outer_exitcond = icmp eq i64 %i.next, 1024
106 br i1 %outer_exitcond, label %exit, label %outer_loop, !llvm.loop !1
112 !1 = distinct !{!1, !2}
113 !2 = !{!"llvm.loop.vectorize.enable", i1 true}