blob: 2abb4194f15954d2223df7bcf80d3a0284283362 [file] [log] [blame]
Dmitri Gribenko56bf2e12012-12-30 02:33:22 +00001; RUN: opt -gvn -disable-output < %s
Chris Lattnercf0b1982009-11-27 22:50:07 +00002
3; PR5631
4
5target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
6target triple = "x86_64-apple-darwin10.0"
7
Chris Lattnerf492ece2010-02-11 05:08:05 +00008define i32* @test1(i8* %name, i32 %namelen, i32* %o, i32 %expected_type) nounwind ssp {
Chris Lattnercf0b1982009-11-27 22:50:07 +00009entry:
10 br i1 undef, label %if.end13, label %while.body.preheader
11
12
13if.end13: ; preds = %if.then6
14 br label %while.body.preheader
15
16while.body.preheader: ; preds = %if.end13, %if.end
17 br label %while.body
18
19while.body: ; preds = %while.body.backedge, %while.body.preheader
20 %o.addr.0 = phi i32* [ undef, %while.body.preheader ], [ %o.addr.0.be, %while.body.backedge ] ; <i32*> [#uses=2]
21 br i1 false, label %return.loopexit, label %lor.lhs.false
22
23lor.lhs.false: ; preds = %while.body
24 %tmp20 = bitcast i32* %o.addr.0 to i32* ; <i32*> [#uses=1]
David Blaikiea79ac142015-02-27 21:17:42 +000025 %tmp22 = load i32, i32* %tmp20 ; <i32> [#uses=0]
Chris Lattnercf0b1982009-11-27 22:50:07 +000026 br i1 undef, label %land.lhs.true24, label %if.end31
27
28land.lhs.true24: ; preds = %lor.lhs.false
29 %call28 = call i32* @parse_object(i8* undef) nounwind ; <i32*> [#uses=0]
30 br i1 undef, label %return.loopexit, label %if.end31
31
32if.end31: ; preds = %land.lhs.true24, %lor.lhs.false
33 br i1 undef, label %return.loopexit, label %if.end41
34
35if.end41: ; preds = %if.end31
36 %tmp43 = bitcast i32* %o.addr.0 to i32* ; <i32*> [#uses=1]
David Blaikiea79ac142015-02-27 21:17:42 +000037 %tmp45 = load i32, i32* %tmp43 ; <i32> [#uses=0]
Chris Lattnercf0b1982009-11-27 22:50:07 +000038 br i1 undef, label %if.then50, label %if.else
39
40if.then50: ; preds = %if.end41
David Blaikiea79ac142015-02-27 21:17:42 +000041 %tmp53 = load i32*, i32** undef ; <i32*> [#uses=1]
Chris Lattnercf0b1982009-11-27 22:50:07 +000042 br label %while.body.backedge
43
44if.else: ; preds = %if.end41
45 br i1 undef, label %if.then62, label %if.else67
46
47if.then62: ; preds = %if.else
48 br label %while.body.backedge
49
50while.body.backedge: ; preds = %if.then62, %if.then50
51 %o.addr.0.be = phi i32* [ %tmp53, %if.then50 ], [ undef, %if.then62 ] ; <i32*> [#uses=1]
52 br label %while.body
53
54if.else67: ; preds = %if.else
55 ret i32* null
56
57return.loopexit: ; preds = %if.end31, %land.lhs.true24, %while.body
58 ret i32* undef
59}
60
61declare i32* @parse_object(i8*)
Chris Lattnerfd75b902009-12-01 06:22:10 +000062
63
64
65
66
67
68%struct.attribute_spec = type { i8*, i32, i32, i8, i8, i8 }
69
70@attribute_tables = external global [4 x %struct.attribute_spec*] ; <[4 x %struct.attribute_spec*]*> [#uses=2]
71
Chris Lattnerf492ece2010-02-11 05:08:05 +000072define void @test2() nounwind {
Chris Lattnerfd75b902009-12-01 06:22:10 +000073entry:
74 br label %bb69.i
75
76bb69.i: ; preds = %bb57.i.preheader
David Blaikie79e6c742015-02-27 19:29:02 +000077 %tmp4 = getelementptr inbounds [4 x %struct.attribute_spec*], [4 x %struct.attribute_spec*]* @attribute_tables, i32 0, i32 undef ; <%struct.attribute_spec**> [#uses=1]
David Blaikiea79ac142015-02-27 21:17:42 +000078 %tmp3 = load %struct.attribute_spec*, %struct.attribute_spec** %tmp4, align 4 ; <%struct.attribute_spec*> [#uses=1]
Chris Lattnerfd75b902009-12-01 06:22:10 +000079 br label %bb65.i
80
81bb65.i: ; preds = %bb65.i.preheader, %bb64.i
82 %storemerge6.i = phi i32 [ 1, %bb64.i ], [ 0, %bb69.i ] ; <i32> [#uses=3]
David Blaikie79e6c742015-02-27 19:29:02 +000083 %scevgep14 = getelementptr inbounds %struct.attribute_spec, %struct.attribute_spec* %tmp3, i32 %storemerge6.i, i32 0 ; <i8**> [#uses=1]
David Blaikiea79ac142015-02-27 21:17:42 +000084 %tmp2 = load i8*, i8** %scevgep14, align 4 ; <i8*> [#uses=0]
85 %tmp = load %struct.attribute_spec*, %struct.attribute_spec** %tmp4, align 4 ; <%struct.attribute_spec*> [#uses=1]
David Blaikie79e6c742015-02-27 19:29:02 +000086 %scevgep1516 = getelementptr inbounds %struct.attribute_spec, %struct.attribute_spec* %tmp, i32 %storemerge6.i, i32 0 ; <i8**> [#uses=0]
Chris Lattnerfd75b902009-12-01 06:22:10 +000087 unreachable
88
89bb64.i: ; Unreachable
90 br label %bb65.i
91
92bb66.i: ; Unreachable
93 br label %bb69.i
94}
Chris Lattner8f770352009-12-09 17:17:26 +000095
96
97
98; rdar://7438974
99
100@g = external global i64, align 8
101
Chris Lattnerf492ece2010-02-11 05:08:05 +0000102define i32* @test3() {
Chris Lattner8f770352009-12-09 17:17:26 +0000103do.end17.i:
David Blaikiea79ac142015-02-27 21:17:42 +0000104 %tmp18.i = load i7*, i7** undef
Chris Lattner8f770352009-12-09 17:17:26 +0000105 %tmp1 = bitcast i7* %tmp18.i to i8*
106 br i1 undef, label %do.body36.i, label %if.then21.i
107
108if.then21.i:
109 %tmp2 = bitcast i7* %tmp18.i to i8*
110 ret i32* undef
111
112do.body36.i:
David Blaikiea79ac142015-02-27 21:17:42 +0000113 %ivar38.i = load i64, i64* @g
Chris Lattner8f770352009-12-09 17:17:26 +0000114 %tmp3 = bitcast i7* %tmp18.i to i8*
115 %add.ptr39.sum.i = add i64 %ivar38.i, 8
David Blaikie79e6c742015-02-27 19:29:02 +0000116 %tmp40.i = getelementptr inbounds i8, i8* %tmp3, i64 %add.ptr39.sum.i
Chris Lattner8f770352009-12-09 17:17:26 +0000117 %tmp4 = bitcast i8* %tmp40.i to i64*
David Blaikiea79ac142015-02-27 21:17:42 +0000118 %tmp41.i = load i64, i64* %tmp4
Chris Lattner8f770352009-12-09 17:17:26 +0000119 br i1 undef, label %if.then48.i, label %do.body57.i
120
121if.then48.i:
122 %call54.i = call i32 @foo2()
123 br label %do.body57.i
124
125do.body57.i:
David Blaikiea79ac142015-02-27 21:17:42 +0000126 %tmp58.i = load i7*, i7** undef
127 %ivar59.i = load i64, i64* @g
Chris Lattner8f770352009-12-09 17:17:26 +0000128 %tmp5 = bitcast i7* %tmp58.i to i8*
129 %add.ptr65.sum.i = add i64 %ivar59.i, 8
David Blaikie79e6c742015-02-27 19:29:02 +0000130 %tmp66.i = getelementptr inbounds i8, i8* %tmp5, i64 %add.ptr65.sum.i
Chris Lattner8f770352009-12-09 17:17:26 +0000131 %tmp6 = bitcast i8* %tmp66.i to i64*
David Blaikiea79ac142015-02-27 21:17:42 +0000132 %tmp67.i = load i64, i64* %tmp6
Chris Lattner8f770352009-12-09 17:17:26 +0000133 ret i32* undef
134}
135
136declare i32 @foo2()
137
Chris Lattnerf492ece2010-02-11 05:08:05 +0000138
139
140define i32 @test4() {
141entry:
142 ret i32 0
143
144dead:
David Blaikie79e6c742015-02-27 19:29:02 +0000145 %P2 = getelementptr i32, i32 *%P2, i32 52
146 %Q2 = getelementptr i32, i32 *%Q2, i32 52
Chris Lattnerf492ece2010-02-11 05:08:05 +0000147 store i32 4, i32* %P2
David Blaikiea79ac142015-02-27 21:17:42 +0000148 %A = load i32, i32* %Q2
Chris Lattnerf492ece2010-02-11 05:08:05 +0000149 br i1 true, label %dead, label %dead2
150
151dead2:
152 ret i32 %A
153}
Chris Lattnerf0d59072011-05-22 07:03:34 +0000154
155
156; PR9841
157define fastcc i8 @test5(i8* %P) nounwind {
158entry:
David Blaikiea79ac142015-02-27 21:17:42 +0000159 %0 = load i8, i8* %P, align 2
Chris Lattnerf0d59072011-05-22 07:03:34 +0000160
David Blaikie79e6c742015-02-27 19:29:02 +0000161 %Q = getelementptr i8, i8* %P, i32 1
David Blaikiea79ac142015-02-27 21:17:42 +0000162 %1 = load i8, i8* %Q, align 1
Chris Lattnerf0d59072011-05-22 07:03:34 +0000163 ret i8 %1
164}
165
Bill Wendling5858b562012-10-23 18:37:11 +0000166
167; Test that a GEP in an unreachable block with the following form doesn't crash
168; GVN:
169;
170; %x = gep %some.type %x, ...
171
172%struct.type = type { i64, i32, i32 }
173
174define fastcc void @func() nounwind uwtable ssp align 2 {
175entry:
176 br label %reachable.bb
177
178;; Unreachable code.
179
180unreachable.bb:
David Blaikie79e6c742015-02-27 19:29:02 +0000181 %gep.val = getelementptr inbounds %struct.type, %struct.type* %gep.val, i64 1
Bill Wendling5858b562012-10-23 18:37:11 +0000182 br i1 undef, label %u2.bb, label %u1.bb
183
184u1.bb:
David Blaikie79e6c742015-02-27 19:29:02 +0000185 %tmp1 = getelementptr inbounds %struct.type, %struct.type* %gep.val, i64 0, i32 0
Bill Wendling5858b562012-10-23 18:37:11 +0000186 store i64 -1, i64* %tmp1, align 8
187 br label %unreachable.bb
188
189u2.bb:
David Blaikiea79ac142015-02-27 21:17:42 +0000190 %0 = load i32, i32* undef, align 4
Bill Wendling5858b562012-10-23 18:37:11 +0000191 %conv.i.i.i.i.i = zext i32 %0 to i64
192 br label %u2.bb
193
194;; Reachable code.
195
196reachable.bb:
197 br label %r1.bb
198
199r1.bb:
200 br label %u2.bb
201}