2 ; RUN: opt < %s -loop-vectorize -force-vector-width=2 -force-vector-interleave=1 -instcombine -debug-only=loop-vectorize -disable-output -print-after=instcombine 2>&1 | FileCheck %s
4 target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
6 ; CHECK-LABEL: vector_gep
7 ; CHECK-NOT: LV: Found scalar instruction: %tmp0 = getelementptr inbounds i32, i32* %b, i64 %i
9 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
10 ; CHECK-NEXT: [[VEC_IND:%.*]] = phi <2 x i64> [ <i64 0, i64 1>, %vector.ph ], [ [[VEC_IND_NEXT:%.*]], %vector.body ]
11 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, i32* %b, <2 x i64> [[VEC_IND]]
12 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds i32*, i32** %a, i64 [[INDEX]]
13 ; CHECK-NEXT: [[TMP3:%.*]] = bitcast i32** [[TMP2]] to <2 x i32*>*
14 ; CHECK-NEXT: store <2 x i32*> [[TMP1]], <2 x i32*>* [[TMP3]], align 8
15 ; CHECK-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 2
16 ; CHECK-NEXT: [[VEC_IND_NEXT]] = add <2 x i64> [[VEC_IND]], <i64 2, i64 2>
17 ; CHECK: br i1 {{.*}}, label %middle.block, label %vector.body
19 define void @vector_gep(i32** %a, i32 *%b, i64 %n) {
24 %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
25 %tmp0 = getelementptr inbounds i32, i32* %b, i64 %i
26 %tmp1 = getelementptr inbounds i32*, i32** %a, i64 %i
27 store i32* %tmp0, i32** %tmp1, align 8
28 %i.next = add nuw nsw i64 %i, 1
29 %cond = icmp slt i64 %i.next, %n
30 br i1 %cond, label %for.body, label %for.end
36 ; CHECK-LABEL: scalar_store
37 ; CHECK: LV: Found scalar instruction: %tmp1 = getelementptr inbounds i32*, i32** %a, i64 %i
38 ; CHECK-NEXT: LV: Found scalar instruction: %tmp0 = getelementptr inbounds i32, i32* %b, i64 %i
39 ; CHECK-NEXT: LV: Found scalar instruction: %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
40 ; CHECK-NEXT: LV: Found scalar instruction: %i.next = add nuw nsw i64 %i, 2
42 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
43 ; CHECK-NEXT: [[OFFSET_IDX:%.*]] = shl i64 [[INDEX]], 1
44 ; CHECK-NEXT: [[TMP4:%.*]] = or i64 [[OFFSET_IDX]], 2
45 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i32, i32* %b, i64 [[OFFSET_IDX]]
46 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, i32* %b, i64 [[TMP4]]
47 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i32*, i32** %a, i64 [[OFFSET_IDX]]
48 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i32*, i32** %a, i64 [[TMP4]]
49 ; CHECK-NEXT: store i32* [[TMP5]], i32** [[TMP7]], align 8
50 ; CHECK-NEXT: store i32* [[TMP6]], i32** [[TMP8]], align 8
51 ; CHECK-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 2
52 ; CHECK: br i1 {{.*}}, label %middle.block, label %vector.body
54 define void @scalar_store(i32** %a, i32 *%b, i64 %n) {
59 %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
60 %tmp0 = getelementptr inbounds i32, i32* %b, i64 %i
61 %tmp1 = getelementptr inbounds i32*, i32** %a, i64 %i
62 store i32* %tmp0, i32** %tmp1, align 8
63 %i.next = add nuw nsw i64 %i, 2
64 %cond = icmp slt i64 %i.next, %n
65 br i1 %cond, label %for.body, label %for.end
71 ; CHECK-LABEL: expansion
72 ; CHECK: LV: Found scalar instruction: %tmp3 = getelementptr inbounds i32*, i32** %tmp2, i64 %i
73 ; CHECK-NEXT: LV: Found scalar instruction: %tmp1 = bitcast i64* %tmp0 to i32*
74 ; CHECK-NEXT: LV: Found scalar instruction: %tmp2 = getelementptr inbounds i32*, i32** %a, i64 0
75 ; CHECK-NEXT: LV: Found scalar instruction: %tmp0 = getelementptr inbounds i64, i64* %b, i64 %i
76 ; CHECK-NEXT: LV: Found scalar instruction: %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
77 ; CHECK-NEXT: LV: Found scalar instruction: %i.next = add nuw nsw i64 %i, 2
79 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
80 ; CHECK-NEXT: [[OFFSET_IDX:%.*]] = shl i64 [[INDEX]], 1
81 ; CHECK-NEXT: [[TMP4:%.*]] = or i64 [[OFFSET_IDX]], 2
82 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i64, i64* %b, i64 [[OFFSET_IDX]]
83 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i64, i64* %b, i64 [[TMP4]]
84 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i32*, i32** %a, i64 [[OFFSET_IDX]]
85 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i32*, i32** %a, i64 [[TMP4]]
86 ; CHECK-NEXT: [[TMP9:%.*]] = bitcast i32** [[TMP7]] to i64**
87 ; CHECK-NEXT: store i64* [[TMP5]], i64** [[TMP9]], align 8
88 ; CHECK-NEXT: [[TMP10:%.*]] = bitcast i32** [[TMP8]] to i64**
89 ; CHECK-NEXT: store i64* [[TMP6]], i64** [[TMP10]], align 8
90 ; CHECK-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 2
91 ; CHECK: br i1 {{.*}}, label %middle.block, label %vector.body
93 define void @expansion(i32** %a, i64 *%b, i64 %n) {
98 %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
99 %tmp0 = getelementptr inbounds i64, i64* %b, i64 %i
100 %tmp1 = bitcast i64* %tmp0 to i32*
101 %tmp2 = getelementptr inbounds i32*, i32** %a, i64 0
102 %tmp3 = getelementptr inbounds i32*, i32** %tmp2, i64 %i
103 store i32* %tmp1, i32** %tmp3, align 8
104 %i.next = add nuw nsw i64 %i, 2
105 %cond = icmp slt i64 %i.next, %n
106 br i1 %cond, label %for.body, label %for.end
112 ; CHECK-LABEL: no_gep_or_bitcast
113 ; CHECK-NOT: LV: Found scalar instruction: %tmp1 = load i32*, i32** %tmp0, align 8
114 ; CHECK: LV: Found scalar instruction: %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
115 ; CHECK-NEXT: LV: Found scalar instruction: %i.next = add nuw nsw i64 %i, 1
116 ; CHECK: vector.body:
117 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
118 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32*, i32** %a, i64 [[INDEX]]
119 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast i32** [[TMP1]] to <2 x i32*>*
120 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x i32*>, <2 x i32*>* [[TMP2]], align 8
121 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <2 x i32*> [[WIDE_LOAD]], i32 0
122 ; CHECK-NEXT: store i32 0, i32* [[TMP3]], align 8
123 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x i32*> [[WIDE_LOAD]], i32 1
124 ; CHECK-NEXT: store i32 0, i32* [[TMP4]], align 8
125 ; CHECK-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 2
126 ; CHECK: br i1 {{.*}}, label %middle.block, label %vector.body
128 define void @no_gep_or_bitcast(i32** noalias %a, i64 %n) {
133 %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
134 %tmp0 = getelementptr inbounds i32*, i32** %a, i64 %i
135 %tmp1 = load i32*, i32** %tmp0, align 8
136 store i32 0, i32* %tmp1, align 8
137 %i.next = add nuw nsw i64 %i, 1
138 %cond = icmp slt i64 %i.next, %n
139 br i1 %cond, label %for.body, label %for.end