1 ; RUN: opt -loop-vectorize -scalable-vectorization=on -dce -instcombine -mtriple aarch64-linux-gnu -mattr=+sve -S %s -o - | FileCheck %s
3 define void @cond_inv_load_i32i32i16(i32* noalias nocapture %a, i32* noalias nocapture readonly %cond, i16* noalias nocapture readonly %inv, i64 %n) #0 {
4 ; CHECK-LABEL: @cond_inv_load_i32i32i16
6 ; CHECK: %[[INVINS:.*]] = insertelement <vscale x 4 x i16*> poison, i16* %inv, i32 0
7 ; CHECK: %[[INVSPLAT:.*]] = shufflevector <vscale x 4 x i16*> %[[INVINS]], <vscale x 4 x i16*> poison, <vscale x 4 x i32> zeroinitializer
9 ; CHECK: %[[GEPCOND:.*]] = getelementptr inbounds i32, i32* %cond, i64 %index
10 ; CHECK-NEXT: %[[GEPCOND2:.*]] = bitcast i32* %[[GEPCOND]] to <vscale x 4 x i32>*
11 ; CHECK-NEXT: %[[CONDVALS:.*]] = load <vscale x 4 x i32>, <vscale x 4 x i32>* %[[GEPCOND2]], align 4
12 ; CHECK-NEXT: %[[MASK:.*]] = icmp ne <vscale x 4 x i32> %[[CONDVALS]],
13 ; CHECK-NEXT: %[[GATHERLOAD:.*]] = call <vscale x 4 x i16> @llvm.masked.gather.nxv4i16.nxv4p0i16(<vscale x 4 x i16*> %[[INVSPLAT]], i32 2, <vscale x 4 x i1> %[[MASK]], <vscale x 4 x i16> undef)
14 ; CHECK-NEXT: %[[GATHERLOAD2:.*]] = sext <vscale x 4 x i16> %[[GATHERLOAD]] to <vscale x 4 x i32>
15 ; CHECK: call void @llvm.masked.store.nxv4i32.p0nxv4i32(<vscale x 4 x i32> %[[GATHERLOAD2]]
19 for.body: ; preds = %entry, %for.inc
20 %i.07 = phi i64 [ %inc, %for.inc ], [ 0, %entry ]
21 %arrayidx = getelementptr inbounds i32, i32* %cond, i64 %i.07
22 %0 = load i32, i32* %arrayidx, align 4
23 %tobool.not = icmp eq i32 %0, 0
24 br i1 %tobool.not, label %for.inc, label %if.then
26 if.then: ; preds = %for.body
27 %1 = load i16, i16* %inv, align 2
28 %conv = sext i16 %1 to i32
29 %arrayidx1 = getelementptr inbounds i32, i32* %a, i64 %i.07
30 store i32 %conv, i32* %arrayidx1, align 4
33 for.inc: ; preds = %for.body, %if.then
34 %inc = add nuw nsw i64 %i.07, 1
35 %exitcond.not = icmp eq i64 %inc, %n
36 br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !0
38 exit: ; preds = %for.inc
42 define void @cond_inv_load_f64f64f64(double* noalias nocapture %a, double* noalias nocapture readonly %cond, double* noalias nocapture readonly %inv, i64 %n) #0 {
43 ; CHECK-LABEL: @cond_inv_load_f64f64f64
45 ; CHECK: %[[INVINS:.*]] = insertelement <vscale x 4 x double*> poison, double* %inv, i32 0
46 ; CHECK: %[[INVSPLAT:.*]] = shufflevector <vscale x 4 x double*> %[[INVINS]], <vscale x 4 x double*> poison, <vscale x 4 x i32> zeroinitializer
48 ; CHECK: %[[GEPCOND:.*]] = getelementptr inbounds double, double* %cond, i64 %index
49 ; CHECK-NEXT: %[[GEPCOND2:.*]] = bitcast double* %[[GEPCOND]] to <vscale x 4 x double>*
50 ; CHECK-NEXT: %[[CONDVALS:.*]] = load <vscale x 4 x double>, <vscale x 4 x double>* %[[GEPCOND2]], align 8
51 ; CHECK-NEXT: %[[MASK:.*]] = fcmp ogt <vscale x 4 x double> %[[CONDVALS]],
52 ; CHECK-NEXT: %[[GATHERLOAD:.*]] = call <vscale x 4 x double> @llvm.masked.gather.nxv4f64.nxv4p0f64(<vscale x 4 x double*> %[[INVSPLAT]], i32 8, <vscale x 4 x i1> %[[MASK]], <vscale x 4 x double> undef)
53 ; CHECK: call void @llvm.masked.store.nxv4f64.p0nxv4f64(<vscale x 4 x double> %[[GATHERLOAD]]
57 for.body: ; preds = %entry, %for.inc
58 %i.08 = phi i64 [ %inc, %for.inc ], [ 0, %entry ]
59 %arrayidx = getelementptr inbounds double, double* %cond, i64 %i.08
60 %0 = load double, double* %arrayidx, align 8
61 %cmp1 = fcmp ogt double %0, 4.000000e-01
62 br i1 %cmp1, label %if.then, label %for.inc
64 if.then: ; preds = %for.body
65 %1 = load double, double* %inv, align 8
66 %arrayidx2 = getelementptr inbounds double, double* %a, i64 %i.08
67 store double %1, double* %arrayidx2, align 8
70 for.inc: ; preds = %for.body, %if.then
71 %inc = add nuw nsw i64 %i.08, 1
72 %exitcond.not = icmp eq i64 %inc, %n
73 br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !0
75 exit: ; preds = %for.inc
79 define void @invariant_load_cond(i32* noalias nocapture %a, i32* nocapture readonly %b, i32* nocapture readonly %cond, i64 %n) #0 {
80 ; CHECK-LABEL: @invariant_load_cond
82 ; CHECK: %[[GEP:.*]] = getelementptr inbounds i32, i32* %b, i64 42
83 ; CHECK-NEXT: %[[SPLATINS:.*]] = insertelement <vscale x 4 x i32*> poison, i32* %[[GEP]], i32 0
84 ; CHECK-NEXT: %[[SPLAT:.*]] = shufflevector <vscale x 4 x i32*> %[[SPLATINS]], <vscale x 4 x i32*> poison, <vscale x 4 x i32> zeroinitializer
85 ; CHECK: %[[LOAD:.*]] = load <vscale x 4 x i32>, <vscale x 4 x i32>*
86 ; CHECK-NEXT: %[[ICMP:.*]] = icmp ne <vscale x 4 x i32> %[[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)
87 ; CHECK: %[[MASKED_LOAD:.*]] = call <vscale x 4 x i32> @llvm.masked.load.nxv4i32.p0nxv4i32(<vscale x 4 x i32>* %[[BITCAST:.*]], i32 4, <vscale x 4 x i1> %[[ICMP]], <vscale x 4 x i32> poison)
88 ; CHECK-NEXT: %[[MASKED_GATHER:.*]] = call <vscale x 4 x i32> @llvm.masked.gather.nxv4i32.nxv4p0i32(<vscale x 4 x i32*> %[[SPLAT]], i32 4, <vscale x 4 x i1> %[[ICMP]], <vscale x 4 x i32> undef)
89 ; CHECK-NEXT: %[[ADD:.*]] = add nsw <vscale x 4 x i32> %[[MASKED_GATHER]], %[[MASKED_LOAD]]
90 ; CHECK: call void @llvm.masked.store.nxv4i32.p0nxv4i32(<vscale x 4 x i32> %[[ADD]], <vscale x 4 x i32>* %[[BITCAST1:.*]], i32 4, <vscale x 4 x i1> %[[ICMP]])
95 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.inc ]
96 %arrayidx1 = getelementptr inbounds i32, i32* %b, i64 42
97 %arrayidx2 = getelementptr inbounds i32, i32* %cond, i64 %iv
98 %0 = load i32, i32* %arrayidx2, align 4
99 %tobool.not = icmp eq i32 %0, 0
100 br i1 %tobool.not, label %for.inc, label %if.then
103 %arrayidx3 = getelementptr inbounds i32, i32* %b, i64 %iv
104 %1 = load i32, i32* %arrayidx3, align 4
105 %2 = load i32, i32* %arrayidx1, align 4
106 %add = add nsw i32 %2, %1
107 %arrayidx4 = getelementptr inbounds i32, i32* %a, i64 %iv
108 store i32 %add, i32* %arrayidx4, align 4
112 %iv.next = add nuw nsw i64 %iv, 1
113 %exitcond.not = icmp eq i64 %iv.next, %n
114 br i1 %exitcond.not, label %for.end, label %for.body, !llvm.loop !0
120 attributes #0 = { vscale_range(0, 16) }
121 !0 = distinct !{!0, !1, !2, !3, !4, !5}
122 !1 = !{!"llvm.loop.mustprogress"}
123 !2 = !{!"llvm.loop.vectorize.width", i32 4}
124 !3 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
125 !4 = !{!"llvm.loop.interleave.count", i32 1}
126 !5 = !{!"llvm.loop.vectorize.enable", i1 true}