1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes='sroa<preserve-cfg>' -S | FileCheck %s --check-prefixes=CHECK,CHECK-PRESERVE-CFG
3 ; RUN: opt < %s -passes='sroa<modify-cfg>' -S | FileCheck %s --check-prefixes=CHECK,CHECK-MODIFY-CFG
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n8:16:32:64"
6 @a = external global i16, align 1
8 declare void @maybe_writes()
10 define void @f2(i1 %c1) {
13 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
15 ; CHECK-NEXT: br label [[CLEANUP:%.*]]
17 ; CHECK-NEXT: [[G_0_SROA_SPECULATE_LOAD_CLEANUP:%.*]] = load i16, ptr @a, align 1
18 ; CHECK-NEXT: switch i32 2, label [[CLEANUP7:%.*]] [
19 ; CHECK-NEXT: i32 0, label [[LBL1:%.*]]
20 ; CHECK-NEXT: i32 2, label [[LBL1]]
23 ; CHECK-NEXT: br label [[LBL1]]
25 ; CHECK-NEXT: [[G_0_SROA_SPECULATED:%.*]] = phi i16 [ [[G_0_SROA_SPECULATE_LOAD_CLEANUP]], [[CLEANUP]] ], [ [[G_0_SROA_SPECULATE_LOAD_CLEANUP]], [[CLEANUP]] ], [ undef, [[IF_ELSE]] ]
26 ; CHECK-NEXT: unreachable
28 ; CHECK-NEXT: ret void
31 %e = alloca i16, align 1
32 br i1 %c1, label %if.then, label %if.else
34 if.then: ; preds = %entry
37 cleanup: ; preds = %if.then
38 switch i32 2, label %cleanup7 [
43 if.else: ; preds = %entry
46 lbl1: ; preds = %if.else, %cleanup, %cleanup
47 %g.0 = phi ptr [ @a, %cleanup ], [ @a, %cleanup ], [ %e, %if.else ]
48 %0 = load i16, ptr %g.0, align 1
51 cleanup7: ; preds = %cleanup
55 define void @f3(i1 %c1) {
58 ; CHECK-NEXT: [[E:%.*]] = alloca i16, align 1
59 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
61 ; CHECK-NEXT: br label [[CLEANUP:%.*]]
63 ; CHECK-NEXT: switch i32 2, label [[CLEANUP7:%.*]] [
64 ; CHECK-NEXT: i32 0, label [[LBL1:%.*]]
65 ; CHECK-NEXT: i32 2, label [[LBL1]]
68 ; CHECK-NEXT: br label [[LBL1]]
70 ; CHECK-NEXT: [[G_0:%.*]] = phi ptr [ @a, [[CLEANUP]] ], [ @a, [[CLEANUP]] ], [ [[E]], [[IF_ELSE]] ]
71 ; CHECK-NEXT: br label [[FINAL:%.*]]
73 ; CHECK-NEXT: [[TMP0:%.*]] = load i16, ptr [[G_0]], align 1
74 ; CHECK-NEXT: unreachable
76 ; CHECK-NEXT: ret void
79 %e = alloca i16, align 1
80 br i1 %c1, label %if.then, label %if.else
82 if.then: ; preds = %entry
85 cleanup: ; preds = %if.then
86 switch i32 2, label %cleanup7 [
91 if.else: ; preds = %entry
94 lbl1: ; preds = %if.else, %cleanup, %cleanup
95 %g.0 = phi ptr [ @a, %cleanup ], [ @a, %cleanup ], [ %e, %if.else ]
99 %0 = load i16, ptr %g.0, align 1
102 cleanup7: ; preds = %cleanup
106 define void @f4(i1 %c1) {
109 ; CHECK-NEXT: [[E:%.*]] = alloca i16, align 1
110 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
112 ; CHECK-NEXT: br label [[CLEANUP:%.*]]
114 ; CHECK-NEXT: switch i32 2, label [[CLEANUP7:%.*]] [
115 ; CHECK-NEXT: i32 0, label [[LBL1:%.*]]
116 ; CHECK-NEXT: i32 2, label [[LBL1]]
119 ; CHECK-NEXT: br label [[LBL1]]
121 ; CHECK-NEXT: [[G_0:%.*]] = phi ptr [ @a, [[CLEANUP]] ], [ @a, [[CLEANUP]] ], [ [[E]], [[IF_ELSE]] ]
122 ; CHECK-NEXT: br label [[FINAL:%.*]]
124 ; CHECK-NEXT: call void @maybe_writes()
125 ; CHECK-NEXT: [[TMP0:%.*]] = load i16, ptr [[G_0]], align 1
126 ; CHECK-NEXT: unreachable
128 ; CHECK-NEXT: ret void
131 %e = alloca i16, align 1
132 br i1 %c1, label %if.then, label %if.else
134 if.then: ; preds = %entry
137 cleanup: ; preds = %if.then
138 switch i32 2, label %cleanup7 [
143 if.else: ; preds = %entry
146 lbl1: ; preds = %if.else, %cleanup, %cleanup
147 %g.0 = phi ptr [ @a, %cleanup ], [ @a, %cleanup ], [ %e, %if.else ]
151 call void @maybe_writes()
152 %0 = load i16, ptr %g.0, align 1
155 cleanup7: ; preds = %cleanup
159 define void @f5(i1 %c1, i1 %c2) {
162 ; CHECK-NEXT: [[E:%.*]] = alloca i16, align 1
163 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
165 ; CHECK-NEXT: br label [[CLEANUP:%.*]]
167 ; CHECK-NEXT: switch i32 2, label [[CLEANUP7:%.*]] [
168 ; CHECK-NEXT: i32 0, label [[LBL1:%.*]]
169 ; CHECK-NEXT: i32 2, label [[LBL1]]
172 ; CHECK-NEXT: br label [[LBL1]]
174 ; CHECK-NEXT: [[G_0:%.*]] = phi ptr [ @a, [[CLEANUP]] ], [ @a, [[CLEANUP]] ], [ [[E]], [[IF_ELSE]] ]
175 ; CHECK-NEXT: br i1 [[C2:%.*]], label [[FINAL:%.*]], label [[CLEANUP7]]
177 ; CHECK-NEXT: [[TMP0:%.*]] = load i16, ptr [[G_0]], align 1
178 ; CHECK-NEXT: unreachable
180 ; CHECK-NEXT: ret void
183 %e = alloca i16, align 1
184 br i1 %c1, label %if.then, label %if.else
186 if.then: ; preds = %entry
189 cleanup: ; preds = %if.then
190 switch i32 2, label %cleanup7 [
195 if.else: ; preds = %entry
198 lbl1: ; preds = %if.else, %cleanup, %cleanup
199 %g.0 = phi ptr [ @a, %cleanup ], [ @a, %cleanup ], [ %e, %if.else ]
200 br i1 %c2, label %final, label %cleanup7
203 %0 = load i16, ptr %g.0, align 1
206 cleanup7: ; preds = %cleanup
210 define void @f6(i1 %c1) {
213 ; CHECK-NEXT: [[E:%.*]] = alloca i16, align 1
214 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
216 ; CHECK-NEXT: br label [[CLEANUP:%.*]]
218 ; CHECK-NEXT: switch i32 2, label [[CLEANUP7:%.*]] [
219 ; CHECK-NEXT: i32 0, label [[LBL1:%.*]]
220 ; CHECK-NEXT: i32 2, label [[LBL1]]
223 ; CHECK-NEXT: br label [[LBL1]]
225 ; CHECK-NEXT: [[G_0:%.*]] = phi ptr [ @a, [[CLEANUP]] ], [ @a, [[CLEANUP]] ], [ [[E]], [[IF_ELSE]] ]
226 ; CHECK-NEXT: br label [[FINAL:%.*]]
227 ; CHECK: unreachable_pred:
228 ; CHECK-NEXT: br label [[FINAL]]
230 ; CHECK-NEXT: call void @maybe_writes()
231 ; CHECK-NEXT: [[TMP0:%.*]] = load i16, ptr [[G_0]], align 1
232 ; CHECK-NEXT: unreachable
234 ; CHECK-NEXT: ret void
237 %e = alloca i16, align 1
238 br i1 %c1, label %if.then, label %if.else
240 if.then: ; preds = %entry
243 cleanup: ; preds = %if.then
244 switch i32 2, label %cleanup7 [
249 if.else: ; preds = %entry
252 lbl1: ; preds = %if.else, %cleanup, %cleanup
253 %g.0 = phi ptr [ @a, %cleanup ], [ @a, %cleanup ], [ %e, %if.else ]
260 call void @maybe_writes()
261 %0 = load i16, ptr %g.0, align 1
264 cleanup7: ; preds = %cleanup
267 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
268 ; CHECK-MODIFY-CFG: {{.*}}
269 ; CHECK-PRESERVE-CFG: {{.*}}