1 ; RUN: opt -simplifycfg -S < %s | FileCheck %s
3 declare void @bar() nounwind
5 define i32 @test1(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
7 %tobool = icmp eq i32 %b, 0
8 br i1 %tobool, label %if.else, label %if.then
10 if.then: ; preds = %entry
11 tail call void @bar() nounwind
14 if.else: ; preds = %entry
15 %tobool3 = icmp eq i32 %d, 0
16 br i1 %tobool3, label %if.end7, label %if.then4
18 if.then4: ; preds = %if.else
19 tail call void @bar() nounwind
22 if.end7: ; preds = %if.else, %if.then4, %if.then
23 %x.0 = phi i32* [ %a, %if.then ], [ %c, %if.then4 ], [ null, %if.else ]
24 %tmp9 = load i32, i32* %x.0
27 ; CHECK-LABEL: @test1(
29 ; CHECK: br label %if.end7
31 ; CHECK: phi i32* [ %a, %if.then ], [ %c, %if.else ]
34 define i32 @test1_no_null_opt(i32* %a, i32 %b, i32* %c, i32 %d) nounwind #0 {
36 %tobool = icmp eq i32 %b, 0
37 br i1 %tobool, label %if.else, label %if.then
39 if.then: ; preds = %entry
40 tail call void @bar() nounwind
43 if.else: ; preds = %entry
44 %tobool3 = icmp eq i32 %d, 0
45 br i1 %tobool3, label %if.end7, label %if.then4
47 if.then4: ; preds = %if.else
48 tail call void @bar() nounwind
51 if.end7: ; preds = %if.else, %if.then4, %if.then
52 %x.0 = phi i32* [ %a, %if.then ], [ %c, %if.then4 ], [ null, %if.else ]
53 %tmp9 = load i32, i32* %x.0
56 ; CHECK-LABEL: @test1_no_null_opt(
60 ; CHECK: br label %if.end7
62 ; CHECK-NEXT: phi i32* [ %a, %if.then ], [ %c, %if.then4 ], [ null, %if.else ]
65 define i32 @test2(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
67 %tobool = icmp eq i32 %b, 0
68 br i1 %tobool, label %if.else, label %if.then
70 if.then: ; preds = %entry
71 tail call void @bar() nounwind
74 if.else: ; preds = %entry
75 %tobool3 = icmp eq i32 %d, 0
76 br i1 %tobool3, label %if.end7, label %if.then4
78 if.then4: ; preds = %if.else
79 tail call void @bar() nounwind
82 if.end7: ; preds = %if.else, %if.then4, %if.then
83 %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
84 %tmp9 = load i32, i32* %x.0
86 ; CHECK-LABEL: @test2(
93 define i32 @test2_no_null_opt(i32* %a, i32 %b, i32* %c, i32 %d) nounwind #0 {
95 %tobool = icmp eq i32 %b, 0
96 br i1 %tobool, label %if.else, label %if.then
98 if.then: ; preds = %entry
99 tail call void @bar() nounwind
102 if.else: ; preds = %entry
103 %tobool3 = icmp eq i32 %d, 0
104 br i1 %tobool3, label %if.end7, label %if.then4
106 if.then4: ; preds = %if.else
107 tail call void @bar() nounwind
110 if.end7: ; preds = %if.else, %if.then4, %if.then
111 %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
112 %tmp9 = load i32, i32* %x.0
114 ; CHECK-LABEL: @test2_no_null_opt(
119 ; CHECK-NEXT: phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
122 define i32 @test3(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
124 %tobool = icmp eq i32 %b, 0
125 br i1 %tobool, label %if.else, label %if.then
127 if.then: ; preds = %entry
128 tail call void @bar() nounwind
131 if.else: ; preds = %entry
132 %tobool3 = icmp eq i32 %d, 0
133 br i1 %tobool3, label %if.end7, label %if.then4
135 if.then4: ; preds = %if.else
136 tail call void @bar() nounwind
139 if.end7: ; preds = %if.else, %if.then4, %if.then
140 %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
141 tail call void @bar() nounwind
142 %tmp9 = load i32, i32* %x.0
144 ; CHECK-LABEL: @test3(
146 ; CHECK: phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
149 define i32 @test3_no_null_opt(i32* %a, i32 %b, i32* %c, i32 %d) nounwind #0 {
151 %tobool = icmp eq i32 %b, 0
152 br i1 %tobool, label %if.else, label %if.then
154 if.then: ; preds = %entry
155 tail call void @bar() nounwind
158 if.else: ; preds = %entry
159 %tobool3 = icmp eq i32 %d, 0
160 br i1 %tobool3, label %if.end7, label %if.then4
162 if.then4: ; preds = %if.else
163 tail call void @bar() nounwind
166 if.end7: ; preds = %if.else, %if.then4, %if.then
167 %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
168 tail call void @bar() nounwind
169 %tmp9 = load i32, i32* %x.0
171 ; CHECK-LABEL: @test3_no_null_opt(
176 ; CHECK-NEXT: phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
179 define i32 @test4(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
181 %tobool = icmp eq i32 %b, 0
182 br i1 %tobool, label %if.else, label %if.then
184 if.then: ; preds = %entry
185 tail call void @bar() nounwind
188 if.else: ; preds = %entry
189 %tobool3 = icmp eq i32 %d, 0
190 br i1 %tobool3, label %if.end7, label %if.then4
192 if.then4: ; preds = %if.else
193 tail call void @bar() nounwind
196 if.end7: ; preds = %if.else, %if.then4, %if.then
197 %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
198 %gep = getelementptr i32, i32* %x.0, i32 10
199 %tmp9 = load i32, i32* %gep
200 %tmp10 = or i32 %tmp9, 1
201 store i32 %tmp10, i32* %gep
203 ; CHECK-LABEL: @test4(
207 define i32 @test4_no_null_opt(i32* %a, i32 %b, i32* %c, i32 %d) nounwind #0 {
209 %tobool = icmp eq i32 %b, 0
210 br i1 %tobool, label %if.else, label %if.then
212 if.then: ; preds = %entry
213 tail call void @bar() nounwind
216 if.else: ; preds = %entry
217 %tobool3 = icmp eq i32 %d, 0
218 br i1 %tobool3, label %if.end7, label %if.then4
220 if.then4: ; preds = %if.else
221 tail call void @bar() nounwind
224 if.end7: ; preds = %if.else, %if.then4, %if.then
225 %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
226 %gep = getelementptr i32, i32* %x.0, i32 10
227 %tmp9 = load i32, i32* %gep
228 %tmp10 = or i32 %tmp9, 1
229 store i32 %tmp10, i32* %gep
231 ; CHECK-LABEL: @test4_no_null_opt(
236 ; CHECK-NEXT: phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
239 attributes #0 = { "null-pointer-is-valid"="true" }