blob: c0f0046a1d2c32bca3fd366cc4ab4f7185a7aef3 [file] [log] [blame]
Benjamin Kramerfb212a62011-08-26 01:22:29 +00001; RUN: opt -simplifycfg -S < %s | FileCheck %s
2
3declare void @bar() nounwind
4
5define i32 @test1(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
6entry:
7 %tobool = icmp eq i32 %b, 0
8 br i1 %tobool, label %if.else, label %if.then
9
10if.then: ; preds = %entry
11 tail call void @bar() nounwind
12 br label %if.end7
13
14if.else: ; preds = %entry
15 %tobool3 = icmp eq i32 %d, 0
16 br i1 %tobool3, label %if.end7, label %if.then4
17
18if.then4: ; preds = %if.else
19 tail call void @bar() nounwind
20 br label %if.end7
21
22if.end7: ; preds = %if.else, %if.then4, %if.then
23 %x.0 = phi i32* [ %a, %if.then ], [ %c, %if.then4 ], [ null, %if.else ]
David Blaikiea79ac142015-02-27 21:17:42 +000024 %tmp9 = load i32, i32* %x.0
Benjamin Kramerfb212a62011-08-26 01:22:29 +000025 ret i32 %tmp9
26
Stephen Linc1c7a132013-07-14 01:42:54 +000027; CHECK-LABEL: @test1(
Benjamin Kramerfb212a62011-08-26 01:22:29 +000028; CHECK: if.else:
29; CHECK: br label %if.end7
30
31; CHECK: phi i32* [ %a, %if.then ], [ %c, %if.else ]
32}
33
34define i32 @test2(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
35entry:
36 %tobool = icmp eq i32 %b, 0
37 br i1 %tobool, label %if.else, label %if.then
38
39if.then: ; preds = %entry
40 tail call void @bar() nounwind
41 br label %if.end7
42
43if.else: ; preds = %entry
44 %tobool3 = icmp eq i32 %d, 0
45 br i1 %tobool3, label %if.end7, label %if.then4
46
47if.then4: ; preds = %if.else
48 tail call void @bar() nounwind
49 br label %if.end7
50
51if.end7: ; preds = %if.else, %if.then4, %if.then
52 %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
David Blaikiea79ac142015-02-27 21:17:42 +000053 %tmp9 = load i32, i32* %x.0
Benjamin Kramerfb212a62011-08-26 01:22:29 +000054 ret i32 %tmp9
Stephen Linc1c7a132013-07-14 01:42:54 +000055; CHECK-LABEL: @test2(
Benjamin Kramerfb212a62011-08-26 01:22:29 +000056; CHECK: if.else:
57; CHECK: unreachable
58
59; CHECK-NOT: phi
60}
61
62define i32 @test3(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
63entry:
64 %tobool = icmp eq i32 %b, 0
65 br i1 %tobool, label %if.else, label %if.then
66
67if.then: ; preds = %entry
68 tail call void @bar() nounwind
69 br label %if.end7
70
71if.else: ; preds = %entry
72 %tobool3 = icmp eq i32 %d, 0
73 br i1 %tobool3, label %if.end7, label %if.then4
74
75if.then4: ; preds = %if.else
76 tail call void @bar() nounwind
77 br label %if.end7
78
79if.end7: ; preds = %if.else, %if.then4, %if.then
80 %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
81 tail call void @bar() nounwind
David Blaikiea79ac142015-02-27 21:17:42 +000082 %tmp9 = load i32, i32* %x.0
Benjamin Kramerfb212a62011-08-26 01:22:29 +000083 ret i32 %tmp9
Stephen Linc1c7a132013-07-14 01:42:54 +000084; CHECK-LABEL: @test3(
Benjamin Kramerfb212a62011-08-26 01:22:29 +000085; CHECK: if.end7:
86; CHECK: phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
87}
Benjamin Kramerd12e82e2012-10-04 16:11:49 +000088
89define i32 @test4(i32* %a, i32 %b, i32* %c, i32 %d) nounwind {
90entry:
91 %tobool = icmp eq i32 %b, 0
92 br i1 %tobool, label %if.else, label %if.then
93
94if.then: ; preds = %entry
95 tail call void @bar() nounwind
96 br label %if.end7
97
98if.else: ; preds = %entry
99 %tobool3 = icmp eq i32 %d, 0
100 br i1 %tobool3, label %if.end7, label %if.then4
101
102if.then4: ; preds = %if.else
103 tail call void @bar() nounwind
104 br label %if.end7
105
106if.end7: ; preds = %if.else, %if.then4, %if.then
107 %x.0 = phi i32* [ %a, %if.then ], [ null, %if.then4 ], [ null, %if.else ]
David Blaikie79e6c742015-02-27 19:29:02 +0000108 %gep = getelementptr i32, i32* %x.0, i32 10
David Blaikiea79ac142015-02-27 21:17:42 +0000109 %tmp9 = load i32, i32* %gep
Benjamin Kramerd12e82e2012-10-04 16:11:49 +0000110 %tmp10 = or i32 %tmp9, 1
111 store i32 %tmp10, i32* %gep
112 ret i32 %tmp9
Stephen Linc1c7a132013-07-14 01:42:54 +0000113; CHECK-LABEL: @test4(
Benjamin Kramerd12e82e2012-10-04 16:11:49 +0000114; CHECK-NOT: phi
115}