1 ; RUN: opt < %s -passes=loop-vectorize -force-vector-width=2 -S | FileCheck %s
3 %s1 = type { [32000 x double], [32000 x double], [32000 x double] }
5 define i32 @load_with_pointer_phi_no_runtime_checks(ptr %data) {
6 ; CHECK-LABEL: @load_with_pointer_phi_no_runtime_checks
13 loop.header: ; preds = %loop.latch, %entry
14 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
15 %iv.next = add nuw nsw i64 %iv, 1
16 %cmp5 = icmp ult i64 %iv, 15999
17 %arrayidx = getelementptr inbounds %s1, ptr %data, i64 0, i32 0, i64 %iv
18 br i1 %cmp5, label %if.then, label %if.else
20 if.then: ; preds = %loop.header
21 %gep.1 = getelementptr inbounds %s1, ptr %data, i64 0, i32 1, i64 %iv
24 if.else: ; preds = %loop.header
25 %gep.2 = getelementptr inbounds %s1, ptr %data, i64 0, i32 2, i64 %iv
28 loop.latch: ; preds = %if.else, %if.then
29 %gep.2.sink = phi ptr [ %gep.2, %if.else ], [ %gep.1, %if.then ]
30 %v8 = load double, ptr %gep.2.sink, align 8
31 %mul16 = fmul double 3.0, %v8
32 store double %mul16, ptr %arrayidx, align 8
33 %exitcond.not = icmp eq i64 %iv.next, 32000
34 br i1 %exitcond.not, label %exit, label %loop.header
36 exit: ; preds = %loop.latch
40 define i32 @store_with_pointer_phi_no_runtime_checks(ptr %data) {
41 ; CHECK-LABEL: @store_with_pointer_phi_no_runtime_checks
48 loop.header: ; preds = %loop.latch, %entry
49 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
50 %iv.next = add nuw nsw i64 %iv, 1
51 %cmp5 = icmp ult i64 %iv, 15999
52 %arrayidx = getelementptr inbounds %s1, ptr %data, i64 0, i32 0, i64 %iv
53 br i1 %cmp5, label %if.then, label %if.else
55 if.then: ; preds = %loop.header
56 %gep.1 = getelementptr inbounds %s1, ptr %data, i64 0, i32 1, i64 %iv
59 if.else: ; preds = %loop.header
60 %gep.2 = getelementptr inbounds %s1, ptr %data, i64 0, i32 2, i64 %iv
63 loop.latch: ; preds = %if.else, %if.then
64 %gep.2.sink = phi ptr [ %gep.2, %if.else ], [ %gep.1, %if.then ]
65 %v8 = load double, ptr %arrayidx, align 8
66 %mul16 = fmul double 3.0, %v8
67 store double %mul16, ptr %gep.2.sink, align 8
68 %exitcond.not = icmp eq i64 %iv.next, 32000
69 br i1 %exitcond.not, label %exit, label %loop.header
71 exit: ; preds = %loop.latch
75 define i32 @store_with_pointer_phi_runtime_checks(ptr %A, ptr %B, ptr %C) {
76 ; CHECK-LABEL: @store_with_pointer_phi_runtime_checks
83 loop.header: ; preds = %loop.latch, %entry
84 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
85 %iv.next = add nuw nsw i64 %iv, 1
86 %cmp5 = icmp ult i64 %iv, 15999
87 %arrayidx = getelementptr inbounds double, ptr %A, i64 %iv
88 br i1 %cmp5, label %if.then, label %if.else
90 if.then: ; preds = %loop.header
91 %gep.1 = getelementptr inbounds double, ptr %B, i64 %iv
94 if.else: ; preds = %loop.header
95 %gep.2 = getelementptr inbounds double, ptr %C, i64 %iv
98 loop.latch: ; preds = %if.else, %if.then
99 %gep.2.sink = phi ptr [ %gep.2, %if.else ], [ %gep.1, %if.then ]
100 %v8 = load double, ptr %arrayidx, align 8
101 %mul16 = fmul double 3.0, %v8
102 store double %mul16, ptr %gep.2.sink, align 8
103 %exitcond.not = icmp eq i64 %iv.next, 32000
104 br i1 %exitcond.not, label %exit, label %loop.header
106 exit: ; preds = %loop.latch
110 define i32 @load_with_pointer_phi_outside_loop(ptr %A, ptr %B, ptr %C, i1 %c.0, i1 %c.1) {
111 ; CHECK-LABEL: @load_with_pointer_phi_outside_loop
112 ; CHECK-NOT: vector.body
115 br i1 %c.0, label %if.then, label %if.else
121 %ptr.select = select i1 %c.1, ptr %C, ptr %B
125 %ptr = phi ptr [ %A, %if.then ], [ %ptr.select, %if.else ]
126 br label %loop.header
128 loop.header: ; preds = %loop.latch, %entry
129 %iv = phi i64 [ 0, %loop.ph ], [ %iv.next, %loop.header ]
130 %iv.next = add nuw nsw i64 %iv, 1
131 %arrayidx = getelementptr inbounds double, ptr %A, i64 %iv
132 %v8 = load double, ptr %ptr, align 8
133 %mul16 = fmul double 3.0, %v8
134 store double %mul16, ptr %arrayidx, align 8
135 %exitcond.not = icmp eq i64 %iv.next, 32000
136 br i1 %exitcond.not, label %exit, label %loop.header
138 exit: ; preds = %loop.latch
142 define i32 @store_with_pointer_phi_outside_loop(ptr %A, ptr %B, ptr %C, i1 %c.0, i1 %c.1) {
143 ; CHECK-LABEL: @store_with_pointer_phi_outside_loop
144 ; CHECK-NOT: vector.body
147 br i1 %c.0, label %if.then, label %if.else
153 %ptr.select = select i1 %c.1, ptr %C, ptr %B
157 %ptr = phi ptr [ %A, %if.then ], [ %ptr.select, %if.else ]
158 br label %loop.header
160 loop.header: ; preds = %loop.latch, %entry
161 %iv = phi i64 [ 0, %loop.ph ], [ %iv.next, %loop.header ]
162 %iv.next = add nuw nsw i64 %iv, 1
163 %arrayidx = getelementptr inbounds double, ptr %A, i64 %iv
164 %v8 = load double, ptr %arrayidx, align 8
165 %mul16 = fmul double 3.0, %v8
166 store double %mul16, ptr %ptr, align 8
167 %exitcond.not = icmp eq i64 %iv.next, 32000
168 br i1 %exitcond.not, label %exit, label %loop.header
170 exit: ; preds = %loop.latch