1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; This is the loop in c++ being vectorize in this file with
5 ;#pragma clang loop vectorize_width(4, fixed)
6 ; for (long int i = N - 1; i >= 0; i--)
12 ; The test checks if the mask is being correctly created, reverted and used
14 ; RUN: opt -passes=loop-vectorize,dce,instcombine -mtriple aarch64-linux-gnu -S \
15 ; RUN: -prefer-predicate-over-epilogue=scalar-epilogue < %s | FileCheck %s
17 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
18 target triple = "aarch64-unknown-linux-gnu"
20 define void @vector_reverse_mask_v4i1(ptr noalias %a, ptr noalias %cond, i64 %N) #0 {
21 ; CHECK-LABEL: @vector_reverse_mask_v4i1(
23 ; CHECK-NEXT: [[CMP7:%.*]] = icmp sgt i64 [[N:%.*]], 0
24 ; CHECK-NEXT: br i1 [[CMP7]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
25 ; CHECK: for.body.preheader:
26 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 8
27 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
29 ; CHECK-NEXT: [[N_VEC:%.*]] = and i64 [[N]], 9223372036854775800
30 ; CHECK-NEXT: [[IND_END:%.*]] = and i64 [[N]], 7
31 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
33 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
34 ; CHECK-NEXT: [[TMP0:%.*]] = xor i64 [[INDEX]], -1
35 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[N]], [[TMP0]]
36 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds double, ptr [[COND:%.*]], i64 [[TMP1]]
37 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds i8, ptr [[TMP2]], i64 -24
38 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds i8, ptr [[TMP2]], i64 -56
39 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x double>, ptr [[TMP3]], align 8
40 ; CHECK-NEXT: [[REVERSE:%.*]] = shufflevector <4 x double> [[WIDE_LOAD]], <4 x double> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
41 ; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x double>, ptr [[TMP4]], align 8
42 ; CHECK-NEXT: [[REVERSE2:%.*]] = shufflevector <4 x double> [[WIDE_LOAD1]], <4 x double> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
43 ; CHECK-NEXT: [[TMP5:%.*]] = fcmp une <4 x double> [[REVERSE]], zeroinitializer
44 ; CHECK-NEXT: [[TMP6:%.*]] = fcmp une <4 x double> [[REVERSE2]], zeroinitializer
45 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr double, ptr [[A:%.*]], i64 [[TMP1]]
46 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr i8, ptr [[TMP7]], i64 -24
47 ; CHECK-NEXT: [[TMP9:%.*]] = getelementptr i8, ptr [[TMP7]], i64 -56
48 ; CHECK-NEXT: [[REVERSE3:%.*]] = shufflevector <4 x i1> [[TMP5]], <4 x i1> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
49 ; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <4 x double> @llvm.masked.load.v4f64.p0(ptr [[TMP8]], i32 8, <4 x i1> [[REVERSE3]], <4 x double> poison)
50 ; CHECK-NEXT: [[REVERSE5:%.*]] = shufflevector <4 x i1> [[TMP6]], <4 x i1> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
51 ; CHECK-NEXT: [[WIDE_MASKED_LOAD6:%.*]] = call <4 x double> @llvm.masked.load.v4f64.p0(ptr [[TMP9]], i32 8, <4 x i1> [[REVERSE5]], <4 x double> poison)
52 ; CHECK-NEXT: [[TMP10:%.*]] = fadd <4 x double> [[WIDE_MASKED_LOAD]], splat (double 1.000000e+00)
53 ; CHECK-NEXT: [[TMP11:%.*]] = fadd <4 x double> [[WIDE_MASKED_LOAD6]], splat (double 1.000000e+00)
54 ; CHECK-NEXT: call void @llvm.masked.store.v4f64.p0(<4 x double> [[TMP10]], ptr [[TMP8]], i32 8, <4 x i1> [[REVERSE3]])
55 ; CHECK-NEXT: call void @llvm.masked.store.v4f64.p0(<4 x double> [[TMP11]], ptr [[TMP9]], i32 8, <4 x i1> [[REVERSE5]])
56 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
57 ; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
58 ; CHECK-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
59 ; CHECK: middle.block:
60 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]]
61 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[SCALAR_PH]]
63 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[N]], [[FOR_BODY_PREHEADER]] ]
64 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
65 ; CHECK: for.cond.cleanup.loopexit:
66 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
67 ; CHECK: for.cond.cleanup:
68 ; CHECK-NEXT: ret void
70 ; CHECK-NEXT: [[I_08_IN:%.*]] = phi i64 [ [[I_08:%.*]], [[FOR_INC:%.*]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
71 ; CHECK-NEXT: [[I_08]] = add nsw i64 [[I_08_IN]], -1
72 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[COND]], i64 [[I_08]]
73 ; CHECK-NEXT: [[TMP13:%.*]] = load double, ptr [[ARRAYIDX]], align 8
74 ; CHECK-NEXT: [[TOBOOL:%.*]] = fcmp une double [[TMP13]], 0.000000e+00
75 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[FOR_INC]]
77 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds double, ptr [[A]], i64 [[I_08]]
78 ; CHECK-NEXT: [[TMP14:%.*]] = load double, ptr [[ARRAYIDX1]], align 8
79 ; CHECK-NEXT: [[ADD:%.*]] = fadd double [[TMP14]], 1.000000e+00
80 ; CHECK-NEXT: store double [[ADD]], ptr [[ARRAYIDX1]], align 8
81 ; CHECK-NEXT: br label [[FOR_INC]]
83 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[I_08_IN]], 1
84 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_COND_CLEANUP_LOOPEXIT]], !llvm.loop [[LOOP4:![0-9]+]]
88 %cmp7 = icmp sgt i64 %N, 0
89 br i1 %cmp7, label %for.body, label %for.cond.cleanup
91 for.cond.cleanup: ; preds = %for.cond.cleanup, %entry
94 for.body: ; preds = %for.body, %entry
95 %i.08.in = phi i64 [ %i.08, %for.inc ], [ %N, %entry ]
96 %i.08 = add nsw i64 %i.08.in, -1
97 %arrayidx = getelementptr inbounds double, ptr %cond, i64 %i.08
98 %0 = load double, ptr %arrayidx, align 8
99 %tobool = fcmp une double %0, 0.000000e+00
100 br i1 %tobool, label %if.then, label %for.inc
102 if.then: ; preds = %for.body
103 %arrayidx1 = getelementptr inbounds double, ptr %a, i64 %i.08
104 %1 = load double, ptr %arrayidx1, align 8
105 %add = fadd double %1, 1.000000e+00
106 store double %add, ptr %arrayidx1, align 8
109 for.inc: ; preds = %for.body, %if.then
110 %cmp = icmp sgt i64 %i.08.in, 1
111 br i1 %cmp, label %for.body, label %for.cond.cleanup, !llvm.loop !0
114 attributes #0 = {"target-cpu"="generic" "target-features"="+neon,+sve" vscale_range(2,0) }
117 !0 = distinct !{!0, !1, !2, !3, !4, !5}
118 !1 = !{!"llvm.loop.mustprogress"}
119 !2 = !{!"llvm.loop.vectorize.width", i32 4}
120 !3 = !{!"llvm.loop.vectorize.scalable.enable", i1 false}
121 !4 = !{!"llvm.loop.vectorize.enable", i1 true}
122 !5 = !{!"llvm.loop.interleave.count", i32 2}