1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
3 ; RUN: opt -S -passes=loop-vectorize -debug-only=loop-vectorize < %s 2>%t | FileCheck %s
4 ; RUN: cat %t | FileCheck %s --check-prefix=VPLANS
6 ; These tests ensure that tail-folding is enabled when the predicate.enable
7 ; loop attribute is set to true.
9 target triple = "aarch64-unknown-linux-gnu"
11 ; VPLANS-LABEL: Checking a loop in 'simple_memset'
12 ; VPLANS: VPlan 'Initial VPlan for VF={vscale x 1,vscale x 2,vscale x 4},UF>=1' {
13 ; VPLANS-NEXT: Live-in vp<[[VFxUF:%.+]]> = VF * UF
14 ; VPLANS-NEXT: vp<[[TC:%[0-9]+]]> = original trip-count
17 ; VPLANS-NEXT: EMIT vp<[[TC]]> = EXPAND SCEV (1 umax %n)
18 ; VPLANS-NEXT: No successors
20 ; VPLANS-NEXT: vector.ph:
21 ; VPLANS-NEXT: EMIT vp<[[NEWTC:%[0-9]+]]> = TC > VF ? TC - VF : 0 vp<[[TC]]>
22 ; VPLANS-NEXT: EMIT vp<[[VF:%[0-9]+]]> = VF * Part + ir<0>
23 ; VPLANS-NEXT: EMIT vp<[[LANEMASK_ENTRY:%[0-9]+]]> = active lane mask vp<[[VF]]>, vp<[[TC]]>
24 ; VPLANS-NEXT: Successor(s): vector loop
26 ; VPLANS-NEXT: <x1> vector loop: {
27 ; VPLANS-NEXT: vector.body:
28 ; VPLANS-NEXT: EMIT vp<[[INDV:%[0-9]+]]> = CANONICAL-INDUCTION
29 ; VPLANS-NEXT: ACTIVE-LANE-MASK-PHI vp<[[LANEMASK_PHI:%[0-9]+]]> = phi vp<[[LANEMASK_ENTRY]]>, vp<[[LANEMASK_LOOP:%[0-9]+]]>
30 ; VPLANS-NEXT: vp<[[STEP:%[0-9]+]]> = SCALAR-STEPS vp<[[INDV]]>, ir<1>
31 ; VPLANS-NEXT: CLONE ir<%gep> = getelementptr ir<%ptr>, vp<[[STEP]]>
32 ; VPLANS-NEXT: vp<[[VEC_PTR:%[0-9]+]]> = vector-pointer ir<%gep>
33 ; VPLANS-NEXT: WIDEN store vp<[[VEC_PTR]]>, ir<%val>, vp<[[LANEMASK_PHI]]>
34 ; VPLANS-NEXT: EMIT vp<[[INDV_UPDATE:%[0-9]+]]> = add vp<[[INDV]]>, vp<[[VFxUF]]>
35 ; VPLANS-NEXT: EMIT vp<[[INC:%[0-9]+]]> = VF * Part + vp<[[INDV]]>
36 ; VPLANS-NEXT: EMIT vp<[[LANEMASK_LOOP]]> = active lane mask vp<[[INC]]>, vp<[[NEWTC]]>
37 ; VPLANS-NEXT: EMIT vp<[[NOT:%[0-9]+]]> = not vp<[[LANEMASK_LOOP]]>
38 ; VPLANS-NEXT: EMIT branch-on-cond vp<[[NOT]]>
39 ; VPLANS-NEXT: No successors
42 define void @simple_memset(i32 %val, ptr %ptr, i64 %n) #0 {
43 ; CHECK-LABEL: @simple_memset(
45 ; CHECK-NEXT: [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[N:%.*]], i64 1)
46 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
48 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
49 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
50 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
51 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
52 ; CHECK-NEXT: [[TMP4:%.*]] = sub i64 [[TMP3]], 1
53 ; CHECK-NEXT: [[N_RND_UP:%.*]] = add i64 [[UMAX]], [[TMP4]]
54 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP1]]
55 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]]
56 ; CHECK-NEXT: [[TMP13:%.*]] = call i64 @llvm.vscale.i64()
57 ; CHECK-NEXT: [[TMP14:%.*]] = mul i64 [[TMP13]], 4
58 ; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
59 ; CHECK-NEXT: [[TMP6:%.*]] = mul i64 [[TMP5]], 4
60 ; CHECK-NEXT: [[TMP7:%.*]] = sub i64 [[UMAX]], [[TMP6]]
61 ; CHECK-NEXT: [[TMP8:%.*]] = icmp ugt i64 [[UMAX]], [[TMP6]]
62 ; CHECK-NEXT: [[TMP9:%.*]] = select i1 [[TMP8]], i64 [[TMP7]], i64 0
63 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 0, i64 [[UMAX]])
64 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <vscale x 4 x i32> poison, i32 [[VAL:%.*]], i64 0
65 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <vscale x 4 x i32> [[BROADCAST_SPLATINSERT]], <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
66 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
68 ; CHECK-NEXT: [[INDEX1:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT2:%.*]], [[VECTOR_BODY]] ]
69 ; CHECK-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <vscale x 4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], [[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], [[VECTOR_BODY]] ]
70 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX1]], 0
71 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr i32, ptr [[PTR:%.*]], i64 [[TMP10]]
72 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr i32, ptr [[TMP11]], i32 0
73 ; CHECK-NEXT: call void @llvm.masked.store.nxv4i32.p0(<vscale x 4 x i32> [[BROADCAST_SPLAT]], ptr [[TMP12]], i32 4, <vscale x 4 x i1> [[ACTIVE_LANE_MASK]])
74 ; CHECK-NEXT: [[INDEX_NEXT2]] = add i64 [[INDEX1]], [[TMP14]]
75 ; CHECK-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <vscale x 4 x i1> @llvm.get.active.lane.mask.nxv4i1.i64(i64 [[INDEX1]], i64 [[TMP9]])
76 ; CHECK-NEXT: [[TMP15:%.*]] = xor <vscale x 4 x i1> [[ACTIVE_LANE_MASK_NEXT]], shufflevector (<vscale x 4 x i1> insertelement (<vscale x 4 x i1> poison, i1 true, i64 0), <vscale x 4 x i1> poison, <vscale x 4 x i32> zeroinitializer)
77 ; CHECK-NEXT: [[TMP16:%.*]] = extractelement <vscale x 4 x i1> [[TMP15]], i32 0
78 ; CHECK-NEXT: br i1 [[TMP16]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
79 ; CHECK: middle.block:
80 ; CHECK-NEXT: br i1 true, label [[WHILE_END_LOOPEXIT:%.*]], label [[SCALAR_PH]]
82 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
83 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
85 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ [[INDEX_NEXT:%.*]], [[WHILE_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
86 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[PTR]], i64 [[INDEX]]
87 ; CHECK-NEXT: store i32 [[VAL]], ptr [[GEP]], align 4
88 ; CHECK-NEXT: [[INDEX_NEXT]] = add nsw i64 [[INDEX]], 1
89 ; CHECK-NEXT: [[CMP10:%.*]] = icmp ult i64 [[INDEX_NEXT]], [[N]]
90 ; CHECK-NEXT: br i1 [[CMP10]], label [[WHILE_BODY]], label [[WHILE_END_LOOPEXIT]], !llvm.loop [[LOOP3:![0-9]+]]
91 ; CHECK: while.end.loopexit:
92 ; CHECK-NEXT: ret void
97 while.body: ; preds = %while.body, %entry
98 %index = phi i64 [ %index.next, %while.body ], [ 0, %entry ]
99 %gep = getelementptr i32, ptr %ptr, i64 %index
100 store i32 %val, ptr %gep
101 %index.next = add nsw i64 %index, 1
102 %cmp10 = icmp ult i64 %index.next, %n
103 br i1 %cmp10, label %while.body, label %while.end.loopexit, !llvm.loop !0
105 while.end.loopexit: ; preds = %while.body
110 attributes #0 = { "target-features"="+sve" }
112 !0 = distinct !{!0, !1}
113 !1 = !{!"llvm.loop.vectorize.predicate.enable", i1 true}