xref: /llvm-project/llvm/test/Transforms/JumpThreading/phi-eq.ll (revision 07e34d2de565a88da2724d52cdcf47b4bca873db)
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.
8
9%struct._GList = type { ptr, ptr, ptr }
10%struct.filter_def = type { ptr, ptr }
11
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
21
22declare void @g_assertion_message(ptr, ptr, i32, ptr, ptr) noreturn
23
24declare void @g_free(ptr)
25
26declare ptr @g_list_first(ptr)
27
28declare noalias ptr @g_malloc(i64)
29
30define void @copy_filter_list(i32 %dest_type, i32 %src_type) nounwind uwtable ssp {
31entry:
32  br label %do.body
33
34do.body:                                          ; preds = %entry
35  %cmp = icmp ne i32 %dest_type, %src_type
36  br i1 %cmp, label %if.then, label %if.else
37
38if.then:                                          ; preds = %do.body
39  br label %if.end
40
41if.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
43  unreachable
44
45if.end:                                           ; preds = %if.then
46  br label %do.end
47
48do.end:                                           ; preds = %if.end
49  switch i32 %dest_type, label %sw.default.i [
50    i32 0, label %sw.bb.i
51    i32 1, label %sw.bb1.i
52    i32 2, label %sw.bb2.i
53    i32 3, label %sw.bb3.i
54  ]
55
56sw.bb.i:                                          ; preds = %do.end
57  br label %get_filter_list.exit
58
59sw.bb1.i:                                         ; preds = %do.end
60  br label %get_filter_list.exit
61
62sw.bb2.i:                                         ; preds = %do.end
63  br label %get_filter_list.exit
64
65sw.bb3.i:                                         ; preds = %do.end
66  br label %get_filter_list.exit
67
68sw.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
70  unreachable
71
72get_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
79  ]
80
81sw.bb.i1:                                         ; preds = %get_filter_list.exit
82  br label %get_filter_list.exit6
83
84sw.bb1.i2:                                        ; preds = %get_filter_list.exit
85  br label %get_filter_list.exit6
86
87sw.bb2.i3:                                        ; preds = %get_filter_list.exit
88  br label %get_filter_list.exit6
89
90sw.bb3.i4:                                        ; preds = %get_filter_list.exit
91  br label %get_filter_list.exit6
92
93sw.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
95  unreachable
96
97; CHECK: get_filter_list.exit
98get_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 ]
100; CHECK: %2 = load
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
106  br label %while.cond
107
108; CHECK: while.cond
109while.cond:                                       ; preds = %while.body, %get_filter_list.exit6
110; CHECK: {{= phi .*%.pr}}
111  %3 = load ptr, ptr %0, align 8
112; CHECK: tobool
113  %tobool = icmp ne ptr %3, null
114  br i1 %tobool, label %while.body, label %while.end
115
116while.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
129  br label %while.cond
130
131while.end:                                        ; preds = %while.cond
132  br label %do.body4
133
134do.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
139
140if.then7:                                         ; preds = %do.body4
141  br label %if.end9
142
143if.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
145  unreachable
146
147if.end9:                                          ; preds = %if.then7
148  br label %do.end10
149
150do.end10:                                         ; preds = %if.end9
151  br label %while.cond11
152
153while.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
157
158while.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
174
175cond.true:                                        ; preds = %while.body13
176  %next = getelementptr inbounds %struct._GList, ptr %cond10, i32 0, i32 1
177  %14 = load ptr, ptr %next, align 8
178  br label %cond.end
179
180cond.false:                                       ; preds = %while.body13
181  br label %cond.end
182
183cond.end:                                         ; preds = %cond.false, %cond.true
184  %cond = phi ptr [ %14, %cond.true ], [ null, %cond.false ]
185  br label %while.cond11
186
187while.end16:                                      ; preds = %while.cond11
188  ret void
189}
190
191declare void @g_assertion_message_expr(ptr, ptr, i32, ptr, ptr) noreturn
192
193declare i32 @g_list_length(ptr)
194
195declare noalias ptr @g_strdup(ptr)
196
197declare ptr @g_list_append(ptr, ptr)
198
199declare ptr @g_list_remove_link(ptr, ptr)
200