1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=loop-vectorize -vectorize-num-stores-pred=2 -prefer-predicate-over-epilogue=predicate-dont-vectorize -S | FileCheck %s
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
6 ; Vectorization with dependence checks.
8 ; Check that a non-power-of-2 MaxVF, calculated based on maximum safe distance,
9 ; does not lead fold-tail to think that no tail will be generated for any chosen
11 ; Dependence distance here is 3 iterations.
12 ; Tiny trip count of 15 divides 3, but any (even) VF will have a tail.
14 ;unsigned char a [15+3];
16 ; for (int j = 0; j < 15; ++j) {
22 @a = common local_unnamed_addr global [18 x i8] zeroinitializer, align 16
24 define void @maxvf3() {
25 ; CHECK-LABEL: @maxvf3(
27 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
29 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
31 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_STORE_CONTINUE6:%.*]] ]
32 ; CHECK-NEXT: [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[PRED_STORE_CONTINUE6]] ]
33 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ule <2 x i32> [[VEC_IND]], <i32 14, i32 14>
34 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <2 x i1> [[TMP0]], i32 0
35 ; CHECK-NEXT: br i1 [[TMP1]], label [[PRED_STORE_IF:%.*]], label [[PRED_STORE_CONTINUE:%.*]]
36 ; CHECK: pred.store.if:
37 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[INDEX]], 0
38 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [18 x i8], ptr @a, i32 0, i32 [[TMP2]]
39 ; CHECK-NEXT: store i8 69, ptr [[TMP3]], align 8
40 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE]]
41 ; CHECK: pred.store.continue:
42 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x i1> [[TMP0]], i32 1
43 ; CHECK-NEXT: br i1 [[TMP4]], label [[PRED_STORE_IF1:%.*]], label [[PRED_STORE_CONTINUE2:%.*]]
44 ; CHECK: pred.store.if1:
45 ; CHECK-NEXT: [[TMP5:%.*]] = add i32 [[INDEX]], 1
46 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds [18 x i8], ptr @a, i32 0, i32 [[TMP5]]
47 ; CHECK-NEXT: store i8 69, ptr [[TMP6]], align 8
48 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE2]]
49 ; CHECK: pred.store.continue2:
50 ; CHECK-NEXT: [[TMP7:%.*]] = add nuw nsw <2 x i32> <i32 3, i32 3>, [[VEC_IND]]
51 ; CHECK-NEXT: [[TMP8:%.*]] = extractelement <2 x i1> [[TMP0]], i32 0
52 ; CHECK-NEXT: br i1 [[TMP8]], label [[PRED_STORE_IF3:%.*]], label [[PRED_STORE_CONTINUE4:%.*]]
53 ; CHECK: pred.store.if3:
54 ; CHECK-NEXT: [[TMP9:%.*]] = extractelement <2 x i32> [[TMP7]], i32 0
55 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds [18 x i8], ptr @a, i32 0, i32 [[TMP9]]
56 ; CHECK-NEXT: store i8 7, ptr [[TMP10]], align 8
57 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE4]]
58 ; CHECK: pred.store.continue4:
59 ; CHECK-NEXT: [[TMP11:%.*]] = extractelement <2 x i1> [[TMP0]], i32 1
60 ; CHECK-NEXT: br i1 [[TMP11]], label [[PRED_STORE_IF5:%.*]], label [[PRED_STORE_CONTINUE6]]
61 ; CHECK: pred.store.if5:
62 ; CHECK-NEXT: [[TMP12:%.*]] = extractelement <2 x i32> [[TMP7]], i32 1
63 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds [18 x i8], ptr @a, i32 0, i32 [[TMP12]]
64 ; CHECK-NEXT: store i8 7, ptr [[TMP13]], align 8
65 ; CHECK-NEXT: br label [[PRED_STORE_CONTINUE6]]
66 ; CHECK: pred.store.continue6:
67 ; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 2
68 ; CHECK-NEXT: [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
69 ; CHECK-NEXT: [[TMP14:%.*]] = icmp eq i32 [[INDEX_NEXT]], 16
70 ; CHECK-NEXT: br i1 [[TMP14]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
71 ; CHECK: middle.block:
72 ; CHECK-NEXT: br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
74 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ 16, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
75 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
77 ; CHECK-NEXT: [[J:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[J_NEXT:%.*]], [[FOR_BODY]] ]
78 ; CHECK-NEXT: [[AJ:%.*]] = getelementptr inbounds [18 x i8], ptr @a, i32 0, i32 [[J]]
79 ; CHECK-NEXT: store i8 69, ptr [[AJ]], align 8
80 ; CHECK-NEXT: [[JP3:%.*]] = add nuw nsw i32 3, [[J]]
81 ; CHECK-NEXT: [[AJP3:%.*]] = getelementptr inbounds [18 x i8], ptr @a, i32 0, i32 [[JP3]]
82 ; CHECK-NEXT: store i8 7, ptr [[AJP3]], align 8
83 ; CHECK-NEXT: [[J_NEXT]] = add nuw nsw i32 [[J]], 1
84 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[J_NEXT]], 15
85 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
87 ; CHECK-NEXT: ret void
93 %j = phi i32 [ 0, %entry ], [ %j.next, %for.body ]
94 %aj = getelementptr inbounds [18 x i8], ptr @a, i32 0, i32 %j
95 store i8 69, ptr %aj, align 8
96 %jp3 = add nuw nsw i32 3, %j
97 %ajp3 = getelementptr inbounds [18 x i8], ptr @a, i32 0, i32 %jp3
98 store i8 7, ptr %ajp3, align 8
99 %j.next = add nuw nsw i32 %j, 1
100 %exitcond = icmp eq i32 %j.next, 15
101 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
107 !0 = distinct !{!0, !1}
108 !1 = !{!"llvm.loop.vectorize.enable", i1 true}