xref: /llvm-project/llvm/test/Transforms/LoopVectorize/AArch64/sve-extract-last-veclane.ll (revision 9cf67f6ea0ff3349ad4a1c094fd30434b4bb0475)
1; RUN: opt -passes=loop-vectorize,dce,instcombine -mtriple aarch64-linux-gnu -S < %s | FileCheck %s
2
3target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
4target triple = "aarch64-unknown-linux-gnu"
5
6define void @inv_store_last_lane(ptr noalias nocapture %a, ptr noalias nocapture %inv, ptr noalias nocapture readonly %b, i64 %n) #0 {
7; CHECK-LABEL: @inv_store_last_lane
8; CHECK: vector.body:
9; CHECK:  store <vscale x 4 x i32> %[[VEC_VAL:.*]], ptr
10; CHECK: middle.block:
11; CHECK: %[[VSCALE:.*]] = call i32 @llvm.vscale.i32()
12; CHECK-NEXT: %[[VSCALE2:.*]] = shl i32 %[[VSCALE]], 2
13; CHECK-NEXT: %[[LAST_LANE:.*]] = add i32 %[[VSCALE2]], -1
14; CHECK-NEXT: %{{.*}} = extractelement <vscale x 4 x i32> %[[VEC_VAL]], i32 %[[LAST_LANE]]
15
16entry:
17  br label %for.body
18
19for.body:                                         ; preds = %for.body.lr.ph, %for.body
20  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
21  %arrayidx = getelementptr inbounds i32, ptr %b, i64 %indvars.iv
22  %0 = load i32, ptr %arrayidx, align 4
23  %mul = shl nsw i32 %0, 1
24  %arrayidx2 = getelementptr inbounds i32, ptr %a, i64 %indvars.iv
25  store i32 %mul, ptr %arrayidx2, align 4
26  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
27  %exitcond.not = icmp eq i64 %indvars.iv.next, %n
28  br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !0
29
30exit:              ; preds = %for.body
31  %arrayidx5 = getelementptr inbounds i32, ptr %inv, i64 42
32  store i32 %mul, ptr %arrayidx5, align 4
33  ret void
34}
35
36define float @ret_last_lane(ptr noalias nocapture %a, ptr noalias nocapture readonly %b, i64 %n) #0 {
37; CHECK-LABEL: @ret_last_lane
38; CHECK: vector.body:
39; CHECK:  store <vscale x 4 x float> %[[VEC_VAL:.*]], ptr
40; CHECK: middle.block:
41; CHECK: %[[VSCALE:.*]] = call i32 @llvm.vscale.i32()
42; CHECK-NEXT: %[[VSCALE2:.*]] = shl i32 %[[VSCALE]], 2
43; CHECK-NEXT: %[[LAST_LANE:.*]] = add i32 %[[VSCALE2]], -1
44; CHECK-NEXT: %{{.*}} = extractelement <vscale x 4 x float> %[[VEC_VAL]], i32 %[[LAST_LANE]]
45
46entry:
47  br label %for.body
48
49for.body:                                         ; preds = %for.body.preheader, %for.body
50  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
51  %arrayidx = getelementptr inbounds float, ptr %b, i64 %indvars.iv
52  %0 = load float, ptr %arrayidx, align 4
53  %mul = fmul float %0, 2.000000e+00
54  %arrayidx2 = getelementptr inbounds float, ptr %a, i64 %indvars.iv
55  store float %mul, ptr %arrayidx2, align 4
56  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
57  %exitcond.not = icmp eq i64 %indvars.iv.next, %n
58  br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !6
59
60exit:                                 ; preds = %for.body, %entry
61  ret float %mul
62}
63
64attributes #0 = { "target-cpu"="generic" "target-features"="+neon,+sve" }
65
66!0 = distinct !{!0, !1, !2, !3, !4, !5}
67!1 = !{!"llvm.loop.mustprogress"}
68!2 = !{!"llvm.loop.vectorize.width", i32 4}
69!3 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
70!4 = !{!"llvm.loop.interleave.count", i32 1}
71!5 = !{!"llvm.loop.vectorize.enable", i1 true}
72!6 = distinct !{!6, !1, !2, !3, !4, !5}
73