1 ; RUN: opt < %s -passes=jump-threading -S | FileCheck %s
2 ; Test whether two consecutive switches with identical structures assign the
3 ; proper value to the proper variable. This is really testing
4 ; Instruction::isIdenticalToWhenDefined, as previously that function was
5 ; returning true if the value part of the operands of two phis were identical,
6 ; even if the incoming blocks were not.
7 ; NB: this function should be pruned down more.
9 %struct._GList = type { ptr, ptr, ptr }
10 %struct.filter_def = type { ptr, ptr }
12 @capture_filters = external hidden global ptr, align 8
13 @display_filters = external hidden global ptr, align 8
14 @.str2 = external hidden unnamed_addr constant [10 x i8], align 1
15 @__PRETTY_FUNCTION__.copy_filter_list = external hidden unnamed_addr constant [62 x i8], align 1
16 @.str12 = external hidden unnamed_addr constant [22 x i8], align 1
17 @.str13 = external hidden unnamed_addr constant [31 x i8], align 1
18 @capture_edited_filters = external hidden global ptr, align 8
19 @display_edited_filters = external hidden global ptr, align 8
20 @__PRETTY_FUNCTION__.get_filter_list = external hidden unnamed_addr constant [44 x i8], align 1
22 declare void @g_assertion_message(ptr, ptr, i32, ptr, ptr) noreturn
24 declare void @g_free(ptr)
26 declare ptr @g_list_first(ptr)
28 declare noalias ptr @g_malloc(i64)
30 define void @copy_filter_list(i32 %dest_type, i32 %src_type) nounwind uwtable ssp {
34 do.body: ; preds = %entry
35 %cmp = icmp ne i32 %dest_type, %src_type
36 br i1 %cmp, label %if.then, label %if.else
38 if.then: ; preds = %do.body
41 if.else: ; preds = %do.body
42 call void @g_assertion_message_expr(ptr null, ptr @.str2, i32 581, ptr @__PRETTY_FUNCTION__.copy_filter_list, ptr @.str12) noreturn
45 if.end: ; preds = %if.then
48 do.end: ; preds = %if.end
49 switch i32 %dest_type, label %sw.default.i [
51 i32 1, label %sw.bb1.i
52 i32 2, label %sw.bb2.i
53 i32 3, label %sw.bb3.i
56 sw.bb.i: ; preds = %do.end
57 br label %get_filter_list.exit
59 sw.bb1.i: ; preds = %do.end
60 br label %get_filter_list.exit
62 sw.bb2.i: ; preds = %do.end
63 br label %get_filter_list.exit
65 sw.bb3.i: ; preds = %do.end
66 br label %get_filter_list.exit
68 sw.default.i: ; preds = %do.end
69 call void @g_assertion_message(ptr null, ptr @.str2, i32 408, ptr @__PRETTY_FUNCTION__.get_filter_list, ptr null) noreturn nounwind
72 get_filter_list.exit: ; preds = %sw.bb3.i, %sw.bb2.i, %sw.bb1.i, %sw.bb.i
73 %0 = phi ptr [ @display_edited_filters, %sw.bb3.i ], [ @capture_edited_filters, %sw.bb2.i ], [ @display_filters, %sw.bb1.i ], [ @capture_filters, %sw.bb.i ]
74 switch i32 %src_type, label %sw.default.i5 [
75 i32 0, label %sw.bb.i1
76 i32 1, label %sw.bb1.i2
77 i32 2, label %sw.bb2.i3
78 i32 3, label %sw.bb3.i4
81 sw.bb.i1: ; preds = %get_filter_list.exit
82 br label %get_filter_list.exit6
84 sw.bb1.i2: ; preds = %get_filter_list.exit
85 br label %get_filter_list.exit6
87 sw.bb2.i3: ; preds = %get_filter_list.exit
88 br label %get_filter_list.exit6
90 sw.bb3.i4: ; preds = %get_filter_list.exit
91 br label %get_filter_list.exit6
93 sw.default.i5: ; preds = %get_filter_list.exit
94 call void @g_assertion_message(ptr null, ptr @.str2, i32 408, ptr @__PRETTY_FUNCTION__.get_filter_list, ptr null) noreturn nounwind
97 ; CHECK: get_filter_list.exit
98 get_filter_list.exit6: ; preds = %sw.bb3.i4, %sw.bb2.i3, %sw.bb1.i2, %sw.bb.i1
99 %1 = phi ptr [ @display_edited_filters, %sw.bb3.i4 ], [ @capture_edited_filters, %sw.bb2.i3 ], [ @display_filters, %sw.bb1.i2 ], [ @capture_filters, %sw.bb.i1 ]
101 %2 = load ptr, ptr %1, align 8
102 ; We should have jump-threading insert an additional load here for the value
103 ; coming out of the first switch, which is picked up by a subsequent phi
104 ; CHECK: %.pr = load ptr, ptr %0
105 ; CHECK-NEXT: br label %while.cond
109 while.cond: ; preds = %while.body, %get_filter_list.exit6
110 ; CHECK: {{= phi .*%.pr}}
111 %3 = load ptr, ptr %0, align 8
113 %tobool = icmp ne ptr %3, null
114 br i1 %tobool, label %while.body, label %while.end
116 while.body: ; preds = %while.cond
117 %4 = load ptr, ptr %0, align 8
118 %5 = load ptr, ptr %0, align 8
119 %call2 = call ptr @g_list_first(ptr %5)
120 %6 = load ptr, ptr %call2, align 8
121 %7 = load ptr, ptr %6, align 8
122 call void @g_free(ptr %7) nounwind
123 %strval.i = getelementptr inbounds %struct.filter_def, ptr %6, i32 0, i32 1
124 %8 = load ptr, ptr %strval.i, align 8
125 call void @g_free(ptr %8) nounwind
126 call void @g_free(ptr %6) nounwind
127 %call.i = call ptr @g_list_remove_link(ptr %4, ptr %call2) nounwind
128 store ptr %call.i, ptr %0, align 8
131 while.end: ; preds = %while.cond
134 do.body4: ; preds = %while.end
135 %9 = load ptr, ptr %0, align 8
136 %call5 = call i32 @g_list_length(ptr %9)
137 %cmp6 = icmp eq i32 %call5, 0
138 br i1 %cmp6, label %if.then7, label %if.else8
140 if.then7: ; preds = %do.body4
143 if.else8: ; preds = %do.body4
144 call void @g_assertion_message_expr(ptr null, ptr @.str2, i32 600, ptr @__PRETTY_FUNCTION__.copy_filter_list, ptr @.str13) noreturn
147 if.end9: ; preds = %if.then7
150 do.end10: ; preds = %if.end9
151 br label %while.cond11
153 while.cond11: ; preds = %cond.end, %do.end10
154 %cond10 = phi ptr [ %cond, %cond.end ], [ %2, %do.end10 ]
155 %tobool12 = icmp ne ptr %cond10, null
156 br i1 %tobool12, label %while.body13, label %while.end16
158 while.body13: ; preds = %while.cond11
159 %10 = load ptr, ptr %cond10, align 8
160 %11 = load ptr, ptr %0, align 8
161 %12 = load ptr, ptr %10, align 8
162 %strval = getelementptr inbounds %struct.filter_def, ptr %10, i32 0, i32 1
163 %13 = load ptr, ptr %strval, align 8
164 %call.i7 = call noalias ptr @g_malloc(i64 16) nounwind
165 %call1.i = call noalias ptr @g_strdup(ptr %12) nounwind
166 store ptr %call1.i, ptr %call.i7, align 8
167 %call2.i = call noalias ptr @g_strdup(ptr %13) nounwind
168 %strval.i9 = getelementptr inbounds %struct.filter_def, ptr %call.i7, i32 0, i32 1
169 store ptr %call2.i, ptr %strval.i9, align 8
170 %call3.i = call ptr @g_list_append(ptr %11, ptr %call.i7) nounwind
171 store ptr %call3.i, ptr %0, align 8
172 %tobool15 = icmp ne ptr %cond10, null
173 br i1 %tobool15, label %cond.true, label %cond.false
175 cond.true: ; preds = %while.body13
176 %next = getelementptr inbounds %struct._GList, ptr %cond10, i32 0, i32 1
177 %14 = load ptr, ptr %next, align 8
180 cond.false: ; preds = %while.body13
183 cond.end: ; preds = %cond.false, %cond.true
184 %cond = phi ptr [ %14, %cond.true ], [ null, %cond.false ]
185 br label %while.cond11
187 while.end16: ; preds = %while.cond11
191 declare void @g_assertion_message_expr(ptr, ptr, i32, ptr, ptr) noreturn
193 declare i32 @g_list_length(ptr)
195 declare noalias ptr @g_strdup(ptr)
197 declare ptr @g_list_append(ptr, ptr)
199 declare ptr @g_list_remove_link(ptr, ptr)