1; RUN: opt -loop-vectorize -dce -instcombine -mtriple aarch64-linux-gnu -mattr=+sve < %s -S 2>%t | FileCheck %s
2
3; RUN: FileCheck --check-prefix=WARN --allow-empty %s <%t
4
5; If this check fails please read test/CodeGen/AArch64/README for instructions on how to resolve it.
6; WARN-NOT: warning
7
8target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
9target triple = "aarch64-unknown-linux-gnu"
10
11define void @cmpsel_i32(i32* noalias nocapture %a, i32* noalias nocapture readonly %b, i64 %n) {
12; CHECK-LABEL: @cmpsel_i32(
13; CHECK-NEXT:  entry:
14; CHECK:       vector.body:
15; CHECK:         [[WIDE_LOAD:%.*]] = load <vscale x 4 x i32>, <vscale x 4 x i32>* {{.*}}, align 4
16; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq <vscale x 4 x i32> [[WIDE_LOAD]], shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> poison, i32 0, i32 0), <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer)
17; CHECK-NEXT:    [[TMP2:%.*]] = select <vscale x 4 x i1> [[TMP1]], <vscale x 4 x i32> shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> poison, i32 2, i32 0), <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer), <vscale x 4 x i32> shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> poison, i32 10, i32 0), <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer)
18; CHECK:         store <vscale x 4 x i32> [[TMP2]], <vscale x 4 x i32>* {{.*}}, align 4
19;
20entry:
21  %cmp7 = icmp sgt i64 %n, 0
22  br i1 %cmp7, label %for.body, label %for.end
23
24for.body:                                         ; preds = %entry, %for.body
25  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
26  %arrayidx = getelementptr inbounds i32, i32* %b, i64 %indvars.iv
27  %0 = load i32, i32* %arrayidx, align 4
28  %tobool.not = icmp eq i32 %0, 0
29  %cond = select i1 %tobool.not, i32 2, i32 10
30  %arrayidx2 = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
31  store i32 %cond, i32* %arrayidx2, align 4
32  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
33  %exitcond.not = icmp eq i64 %indvars.iv.next, %n
34  br i1 %exitcond.not, label %for.end.loopexit, label %for.body, !llvm.loop !0
35
36for.end.loopexit:                                 ; preds = %for.body
37  br label %for.end
38
39for.end:                                          ; preds = %for.end.loopexit, %entry
40  ret void
41}
42
43define void @cmpsel_f32(float* noalias nocapture %a, float* noalias nocapture readonly %b, i64 %n) {
44; CHECK-LABEL: @cmpsel_f32(
45; CHECK-NEXT:  entry:
46; CHECK:       vector.body:
47; CHECK:         [[WIDE_LOAD:%.*]] = load <vscale x 4 x float>, <vscale x 4 x float>* {{.*}}, align 4
48; CHECK-NEXT:    [[TMP1:%.*]] = fcmp ogt <vscale x 4 x float> [[WIDE_LOAD]], shufflevector (<vscale x 4 x float> insertelement (<vscale x 4 x float> poison, float 3.000000e+00, i32 0), <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer)
49; CHECK-NEXT:    [[TMP2:%.*]] = select <vscale x 4 x i1> [[TMP1]], <vscale x 4 x float> shufflevector (<vscale x 4 x float> insertelement (<vscale x 4 x float> poison, float 1.000000e+01, i32 0), <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer), <vscale x 4 x float> shufflevector (<vscale x 4 x float> insertelement (<vscale x 4 x float> poison, float 2.000000e+00, i32 0), <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer)
50; CHECK:         store <vscale x 4 x float> [[TMP2]], <vscale x 4 x float>* {{.*}}, align 4
51
52entry:
53  %cmp8 = icmp sgt i64 %n, 0
54  br i1 %cmp8, label %for.body, label %for.end
55
56for.body:                                         ; preds = %entry, %for.body
57  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
58  %arrayidx = getelementptr inbounds float, float* %b, i64 %indvars.iv
59  %0 = load float, float* %arrayidx, align 4
60  %cmp1 = fcmp ogt float %0, 3.000000e+00
61  %conv = select i1 %cmp1, float 1.000000e+01, float 2.000000e+00
62  %arrayidx3 = getelementptr inbounds float, float* %a, i64 %indvars.iv
63  store float %conv, float* %arrayidx3, align 4
64  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
65  %exitcond.not = icmp eq i64 %indvars.iv.next, %n
66  br i1 %exitcond.not, label %for.end, label %for.body, !llvm.loop !6
67
68for.end:                                          ; preds = %for.body, %entry
69  ret void
70}
71
72!0 = distinct !{!0, !1, !2, !3, !4, !5}
73!1 = !{!"llvm.loop.mustprogress"}
74!2 = !{!"llvm.loop.vectorize.width", i32 4}
75!3 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
76!4 = !{!"llvm.loop.interleave.count", i32 1}
77!5 = !{!"llvm.loop.vectorize.enable", i1 true}
78!6 = distinct !{!6, !1, !2, !3, !4, !5}
79