1*cee313d2SEric Christopher; RUN: opt < %s -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -instcombine -S | FileCheck %s
2*cee313d2SEric Christopher
3*cee313d2SEric Christophertarget datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
4*cee313d2SEric Christopher
5*cee313d2SEric Christopher; CHECK-LABEL: @vector_gep_stored(
6*cee313d2SEric Christopher; CHECK:       vector.body:
7*cee313d2SEric Christopher; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
8*cee313d2SEric Christopher; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %vector.ph ], [ [[VEC_IND_NEXT:%.*]], %vector.body ]
9*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i32, i32* %b, <4 x i64> [[VEC_IND]]
10*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32*, i32** %a, i64 [[INDEX]]
11*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i32** [[TMP2]] to <4 x i32*>*
12*cee313d2SEric Christopher; CHECK-NEXT:    store <4 x i32*> [[TMP1]], <4 x i32*>* [[TMP3]], align 8
13*cee313d2SEric Christopher; CHECK-NEXT:    [[INDEX_NEXT]] = add i64 [[INDEX]], 4
14*cee313d2SEric Christopher; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <4 x i64> [[VEC_IND]], <i64 4, i64 4, i64 4, i64 4>
15*cee313d2SEric Christopher; CHECK:         br i1 {{.*}}, label %middle.block, label %vector.body
16*cee313d2SEric Christopher;
17*cee313d2SEric Christopherdefine void @vector_gep_stored(i32** %a, i32 *%b, i64 %n) {
18*cee313d2SEric Christopherentry:
19*cee313d2SEric Christopher  br label %for.body
20*cee313d2SEric Christopher
21*cee313d2SEric Christopherfor.body:
22*cee313d2SEric Christopher  %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
23*cee313d2SEric Christopher  %tmp0 = getelementptr inbounds i32, i32* %b, i64 %i
24*cee313d2SEric Christopher  %tmp1 = getelementptr inbounds i32*, i32** %a, i64 %i
25*cee313d2SEric Christopher  store i32* %tmp0, i32** %tmp1, align 8
26*cee313d2SEric Christopher  %i.next = add nuw nsw i64 %i, 1
27*cee313d2SEric Christopher  %cond = icmp slt i64 %i.next, %n
28*cee313d2SEric Christopher  br i1 %cond, label %for.body, label %for.end
29*cee313d2SEric Christopher
30*cee313d2SEric Christopherfor.end:
31*cee313d2SEric Christopher  ret void
32*cee313d2SEric Christopher}
33*cee313d2SEric Christopher
34*cee313d2SEric Christopher; CHECK-LABEL: @uniform_vector_gep_stored(
35*cee313d2SEric Christopher; CHECK:       vector.body:
36*cee313d2SEric Christopher; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
37*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i32, i32* %b, i64 1
38*cee313d2SEric Christopher; CHECK-NEXT:    [[DOTSPLATINSERT:%.*]] = insertelement <4 x i32*> undef, i32* [[TMP1]], i32 0
39*cee313d2SEric Christopher; CHECK-NEXT:    [[DOTSPLAT:%.*]] = shufflevector <4 x i32*> [[DOTSPLATINSERT]], <4 x i32*> undef, <4 x i32> zeroinitializer
40*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32*, i32** %a, i64 [[INDEX]]
41*cee313d2SEric Christopher; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i32** [[TMP2]] to <4 x i32*>*
42*cee313d2SEric Christopher; CHECK-NEXT:    store <4 x i32*> [[DOTSPLAT]], <4 x i32*>* [[TMP3]], align 8
43*cee313d2SEric Christopher; CHECK-NEXT:    [[INDEX_NEXT]] = add i64 [[INDEX]], 4
44*cee313d2SEric Christopher; CHECK:         br i1 {{.*}}, label %middle.block, label %vector.body
45*cee313d2SEric Christopher;
46*cee313d2SEric Christopherdefine void @uniform_vector_gep_stored(i32** %a, i32 *%b, i64 %n) {
47*cee313d2SEric Christopherentry:
48*cee313d2SEric Christopher  br label %for.body
49*cee313d2SEric Christopher
50*cee313d2SEric Christopherfor.body:
51*cee313d2SEric Christopher  %i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
52*cee313d2SEric Christopher  %tmp0 = getelementptr inbounds i32, i32* %b, i64 1
53*cee313d2SEric Christopher  %tmp1 = getelementptr inbounds i32*, i32** %a, i64 %i
54*cee313d2SEric Christopher  store i32* %tmp0, i32** %tmp1, align 8
55*cee313d2SEric Christopher  %i.next = add nuw nsw i64 %i, 1
56*cee313d2SEric Christopher  %cond = icmp slt i64 %i.next, %n
57*cee313d2SEric Christopher  br i1 %cond, label %for.body, label %for.end
58*cee313d2SEric Christopher
59*cee313d2SEric Christopherfor.end:
60*cee313d2SEric Christopher  ret void
61*cee313d2SEric Christopher}
62