1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -loop-vectorize -force-vector-width=2 -force-vector-interleave=1 -S %s | FileCheck %s
4 ; Make sure LV does not crash when creating runtime checks involving values from
6 define i16 @test(i16** %arg, i64 %N) {
9 ; CHECK-NEXT: br label [[OUTER:%.*]]
11 ; CHECK-NEXT: [[L_1:%.*]] = load i16*, i16** [[ARG:%.*]], align 8
12 ; CHECK-NEXT: [[L_2:%.*]] = load i16*, i16** [[ARG]], align 8
13 ; CHECK-NEXT: [[C_1:%.*]] = call i1 @cond()
14 ; CHECK-NEXT: br i1 [[C_1]], label [[OUTER_BACKEDGE:%.*]], label [[INNER_PREHEADER:%.*]]
15 ; CHECK: outer.backedge:
16 ; CHECK-NEXT: br label [[OUTER]]
17 ; CHECK: inner.preheader:
18 ; CHECK-NEXT: br label [[INNER:%.*]]
20 ; CHECK-NEXT: [[C_2:%.*]] = call i1 @cond()
21 ; CHECK-NEXT: br i1 [[C_2]], label [[OUTER_LATCH:%.*]], label [[INNER_BB:%.*]]
23 ; CHECK-NEXT: [[C_3:%.*]] = call i1 @cond()
24 ; CHECK-NEXT: br i1 [[C_3]], label [[LOOP_3_PREHEADER:%.*]], label [[INNER_LATCH:%.*]]
25 ; CHECK: loop.3.preheader:
26 ; CHECK-NEXT: [[L_1_LCSSA10:%.*]] = phi i16* [ [[L_1]], [[INNER_BB]] ]
27 ; CHECK-NEXT: [[L_1_LCSSA:%.*]] = phi i16* [ [[L_1]], [[INNER_BB]] ]
28 ; CHECK-NEXT: [[L_2_LCSSA:%.*]] = phi i16* [ [[L_2]], [[INNER_BB]] ]
29 ; CHECK-NEXT: [[L_2_LCSSA3:%.*]] = bitcast i16* [[L_2_LCSSA]] to i8*
30 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[N:%.*]], 1
31 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP0]], 2
32 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
33 ; CHECK: vector.memcheck:
34 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i16, i16* [[L_2_LCSSA]], i64 1
35 ; CHECK-NEXT: [[SCEVGEP4:%.*]] = bitcast i16* [[SCEVGEP]] to i8*
36 ; CHECK-NEXT: [[SCEVGEP5:%.*]] = getelementptr i16, i16* [[L_1_LCSSA]], i64 1
37 ; CHECK-NEXT: [[SCEVGEP58:%.*]] = bitcast i16* [[SCEVGEP5]] to i8*
38 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[N]], 2
39 ; CHECK-NEXT: [[SCEVGEP9:%.*]] = getelementptr i16, i16* [[L_1_LCSSA10]], i64 [[TMP1]]
40 ; CHECK-NEXT: [[SCEVGEP912:%.*]] = bitcast i16* [[SCEVGEP9]] to i8*
41 ; CHECK-NEXT: [[BOUND0:%.*]] = icmp ult i8* [[L_2_LCSSA3]], [[SCEVGEP912]]
42 ; CHECK-NEXT: [[BOUND1:%.*]] = icmp ult i8* [[SCEVGEP58]], [[SCEVGEP4]]
43 ; CHECK-NEXT: [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
44 ; CHECK-NEXT: [[MEMCHECK_CONFLICT:%.*]] = and i1 [[FOUND_CONFLICT]], true
45 ; CHECK-NEXT: br i1 [[MEMCHECK_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
47 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TMP0]], 2
48 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[TMP0]], [[N_MOD_VF]]
49 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
51 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
52 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 0
53 ; CHECK-NEXT: [[TMP3:%.*]] = add nuw nsw i64 [[TMP2]], 1
54 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds i16, i16* [[L_1]], i64 [[TMP3]]
55 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i16, i16* [[TMP4]], i32 0
56 ; CHECK-NEXT: [[TMP6:%.*]] = bitcast i16* [[TMP5]] to <2 x i16>*
57 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x i16>, <2 x i16>* [[TMP6]], align 2, !alias.scope !0
58 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i16, i16* [[L_2]], i64 0
59 ; CHECK-NEXT: [[TMP8:%.*]] = extractelement <2 x i16> [[WIDE_LOAD]], i32 0
60 ; CHECK-NEXT: store i16 [[TMP8]], i16* [[TMP7]], align 2, !alias.scope !3, !noalias !0
61 ; CHECK-NEXT: [[TMP9:%.*]] = extractelement <2 x i16> [[WIDE_LOAD]], i32 1
62 ; CHECK-NEXT: store i16 [[TMP9]], i16* [[TMP7]], align 2, !alias.scope !3, !noalias !0
63 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
64 ; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
65 ; CHECK-NEXT: br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
66 ; CHECK: middle.block:
67 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[TMP0]], [[N_VEC]]
68 ; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT_LOOPEXIT:%.*]], label [[SCALAR_PH]]
70 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_3_PREHEADER]] ], [ 0, [[VECTOR_MEMCHECK]] ]
71 ; CHECK-NEXT: br label [[LOOP_3:%.*]]
73 ; CHECK-NEXT: [[C_4:%.*]] = call i1 @cond()
74 ; CHECK-NEXT: br i1 [[C_4]], label [[EXIT_LOOPEXIT1:%.*]], label [[INNER]]
76 ; CHECK-NEXT: br label [[OUTER_BACKEDGE]]
78 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], [[LOOP_3]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
79 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
80 ; CHECK-NEXT: [[C_5:%.*]] = icmp ult i64 [[IV]], [[N]]
81 ; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i16, i16* [[L_1_LCSSA]], i64 [[IV_NEXT]]
82 ; CHECK-NEXT: [[LOOP_L_1:%.*]] = load i16, i16* [[GEP_1]], align 2
83 ; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr inbounds i16, i16* [[L_2_LCSSA]], i64 0
84 ; CHECK-NEXT: store i16 [[LOOP_L_1]], i16* [[GEP_2]], align 2
85 ; CHECK-NEXT: br i1 [[C_5]], label [[LOOP_3]], label [[EXIT_LOOPEXIT]], !llvm.loop [[LOOP7:![0-9]+]]
86 ; CHECK: exit.loopexit:
87 ; CHECK-NEXT: br label [[EXIT:%.*]]
88 ; CHECK: exit.loopexit1:
89 ; CHECK-NEXT: [[L_1_LCSSA6:%.*]] = phi i16* [ [[L_1]], [[INNER_LATCH]] ]
90 ; CHECK-NEXT: br label [[EXIT]]
92 ; CHECK-NEXT: [[L_17:%.*]] = phi i16* [ [[L_1_LCSSA6]], [[EXIT_LOOPEXIT1]] ], [ [[L_1_LCSSA]], [[EXIT_LOOPEXIT]] ]
93 ; CHECK-NEXT: [[L_3:%.*]] = load i16, i16* [[L_17]], align 2
94 ; CHECK-NEXT: ret i16 [[L_3]]
100 %l.1 = load i16*, i16** %arg, align 8
101 %l.2 = load i16*, i16** %arg, align 8
102 %c.1 = call i1 @cond()
103 br i1 %c.1, label %outer, label %inner
105 inner: ; preds = %bb15, %bb1
106 %c.2 = call i1 @cond()
107 br i1 %c.2, label %outer.latch, label %inner.bb
109 inner.bb: ; preds = %bb3
110 %c.3 = call i1 @cond()
111 br i1 %c.3, label %loop.3, label %inner.latch
113 inner.latch: ; preds = %bb4
114 %c.4 = call i1 @cond()
115 br i1 %c.4, label %exit, label %inner
117 outer.latch: ; preds = %bb3
120 loop.3: ; preds = %bb9, %bb4
121 %iv = phi i64 [ %iv.next, %loop.3 ], [ 0, %inner.bb ]
122 %iv.next = add nsw nuw i64 %iv, 1
123 %c.5 = icmp ult i64 %iv, %N
124 %gep.1 = getelementptr inbounds i16, i16* %l.1, i64 %iv.next
125 %loop.l.1 = load i16, i16* %gep.1, align 2
126 %gep.2 = getelementptr inbounds i16, i16* %l.2, i64 0
127 store i16 %loop.l.1, i16* %gep.2 , align 2
128 br i1 %c.5, label %loop.3, label %exit
130 exit: ; preds = %bb15, %bb5
131 %l.3 = load i16, i16* %l.1, align 2