1; REQUIRES: asserts
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
3
4target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
5
6; CHECK-LABEL: phi_two_incoming_values
7; CHECK:       LV: Found an estimated cost of 1 for VF 2 For instruction: %i = phi i64 [ %i.next, %if.end ], [ 0, %entry ]
8; CHECK:       LV: Found an estimated cost of 1 for VF 2 For instruction: %tmp5 = phi i32 [ %tmp1, %for.body ], [ %tmp4, %if.then ]
9; CHECK:       vector.body:
10; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
11; CHECK:         [[WIDE_LOAD:%.*]] = load <2 x i32>, <2 x i32>* {{.*}}
12; CHECK:         [[TMP5:%.*]] = icmp sgt <2 x i32> [[WIDE_LOAD]], zeroinitializer
13; CHECK-NEXT:    [[TMP6:%.*]] = zext <2 x i1> [[TMP5]] to <2 x i32>
14; CHECK-NEXT:    [[PREDPHI:%.*]] = add <2 x i32> [[WIDE_LOAD]], [[TMP6]]
15; CHECK:         store <2 x i32> [[PREDPHI]], <2 x i32>* {{.*}}
16; CHECK-NEXT:    [[INDEX_NEXT]] = add i64 [[INDEX]], 2
17;
18define void @phi_two_incoming_values(i32* %a, i32* %b, i64 %n) {
19entry:
20  br label %for.body
21
22for.body:
23  %i = phi i64 [ %i.next, %if.end ], [ 0, %entry ]
24  %tmp0 = getelementptr inbounds i32, i32* %a, i64 %i
25  %tmp1 = load i32, i32* %tmp0, align 4
26  %tmp2 = getelementptr inbounds i32, i32* %b, i64 %i
27  %tmp3 = icmp sgt i32 %tmp1, 0
28  br i1 %tmp3, label %if.then, label %if.end
29
30if.then:
31  %tmp4 = add i32 %tmp1, 1
32  br label %if.end
33
34if.end:
35  %tmp5 = phi i32 [ %tmp1, %for.body ], [ %tmp4, %if.then ]
36  store i32 %tmp5, i32* %tmp2, align 4
37  %i.next = add i64 %i, 1
38  %cond = icmp eq i64 %i, %n
39  br i1 %cond, label %for.end, label %for.body
40
41for.end:
42  ret void
43}
44
45; CHECK-LABEL: phi_three_incoming_values
46; CHECK:       LV: Found an estimated cost of 1 for VF 2 For instruction: %i = phi i64 [ %i.next, %if.end ], [ 0, %entry ]
47; CHECK:       LV: Found an estimated cost of 2 for VF 2 For instruction: %tmp8 = phi i32 [ 9, %for.body ], [ 3, %if.then ], [ %tmp7, %if.else ]
48; CHECK:       vector.body:
49; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
50; CHECK:         [[PREDPHI:%.*]] = select <2 x i1> {{.*}}, <2 x i32> <i32 3, i32 3>, <2 x i32> <i32 9, i32 9>
51; CHECK:         [[PREDPHI7:%.*]] = select <2 x i1> {{.*}}, <2 x i32> {{.*}}, <2 x i32> [[PREDPHI]]
52; CHECK:         store <2 x i32> [[PREDPHI7]], <2 x i32>* {{.*}}
53; CHECK-NEXT:    [[INDEX_NEXT]] = add i64 [[INDEX]], 2
54;
55define void @phi_three_incoming_values(i32* %a, i32* %b, i64 %n) {
56entry:
57  br label %for.body
58
59for.body:
60  %i = phi i64 [ %i.next, %if.end ], [ 0, %entry ]
61  %tmp0 = getelementptr inbounds i32, i32* %a, i64 %i
62  %tmp1 = load i32, i32* %tmp0, align 4
63  %tmp2 = getelementptr inbounds i32, i32* %b, i64 %i
64  %tmp3 = load i32, i32* %tmp2, align 4
65  %tmp4 = icmp sgt i32 %tmp1, %tmp3
66  br i1 %tmp4, label %if.then, label %if.end
67
68if.then:
69  %tmp5 = icmp sgt i32 %tmp1, 19
70  br i1 %tmp5, label %if.end, label %if.else
71
72if.else:
73  %tmp6 = icmp slt i32 %tmp3, 4
74  %tmp7 = select i1 %tmp6, i32 4, i32 5
75  br label %if.end
76
77if.end:
78  %tmp8 = phi i32 [ 9, %for.body ], [ 3, %if.then ], [ %tmp7, %if.else ]
79  store i32 %tmp8, i32* %tmp0, align 4
80  %i.next = add i64 %i, 1
81  %cond = icmp eq i64 %i, %n
82  br i1 %cond, label %for.end, label %for.body
83
84for.end:
85  ret void
86}
87