1 ; RUN: opt -passes=gvn -disable-output < %s
5 target 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"
6 target triple = "x86_64-apple-darwin10.0"
8 define ptr @test1(ptr %name, i32 %namelen, ptr %o, i32 %expected_type, i1 %arg) nounwind ssp {
10 br i1 %arg, label %if.end13, label %while.body.preheader
13 if.end13: ; preds = %if.then6
14 br label %while.body.preheader
16 while.body.preheader: ; preds = %if.end13, %if.end
19 while.body: ; preds = %while.body.backedge, %while.body.preheader
20 %o.addr.0 = phi ptr [ undef, %while.body.preheader ], [ %o.addr.0.be, %while.body.backedge ] ; <ptr> [#uses=2]
21 br i1 false, label %return.loopexit, label %lor.lhs.false
23 lor.lhs.false: ; preds = %while.body
24 %tmp22 = load i32, ptr %o.addr.0 ; <i32> [#uses=0]
25 br i1 %arg, label %land.lhs.true24, label %if.end31
27 land.lhs.true24: ; preds = %lor.lhs.false
28 %call28 = call ptr @parse_object(ptr undef) nounwind ; <ptr> [#uses=0]
29 br i1 %arg, label %return.loopexit, label %if.end31
31 if.end31: ; preds = %land.lhs.true24, %lor.lhs.false
32 br i1 %arg, label %return.loopexit, label %if.end41
34 if.end41: ; preds = %if.end31
35 %tmp45 = load i32, ptr %o.addr.0 ; <i32> [#uses=0]
36 br i1 %arg, label %if.then50, label %if.else
38 if.then50: ; preds = %if.end41
39 %tmp53 = load ptr, ptr undef ; <ptr> [#uses=1]
40 br label %while.body.backedge
42 if.else: ; preds = %if.end41
43 br i1 %arg, label %if.then62, label %if.else67
45 if.then62: ; preds = %if.else
46 br label %while.body.backedge
48 while.body.backedge: ; preds = %if.then62, %if.then50
49 %o.addr.0.be = phi ptr [ %tmp53, %if.then50 ], [ undef, %if.then62 ] ; <ptr> [#uses=1]
52 if.else67: ; preds = %if.else
55 return.loopexit: ; preds = %if.end31, %land.lhs.true24, %while.body
59 declare ptr @parse_object(ptr)
66 %struct.attribute_spec = type { ptr, i32, i32, i8, i8, i8 }
68 @attribute_tables = external global [4 x ptr] ; <ptr> [#uses=2]
70 define void @test2() nounwind {
74 bb69.i: ; preds = %bb57.i.preheader
75 %tmp4 = getelementptr inbounds [4 x ptr], ptr @attribute_tables, i32 0, i32 undef ; <ptr> [#uses=1]
76 %tmp3 = load ptr, ptr %tmp4, align 4 ; <ptr> [#uses=1]
79 bb65.i: ; preds = %bb65.i.preheader, %bb64.i
80 %storemerge6.i = phi i32 [ 1, %bb64.i ], [ 0, %bb69.i ] ; <i32> [#uses=3]
81 %scevgep14 = getelementptr inbounds %struct.attribute_spec, ptr %tmp3, i32 %storemerge6.i, i32 0 ; <ptr> [#uses=1]
82 %tmp2 = load ptr, ptr %scevgep14, align 4 ; <ptr> [#uses=0]
83 %tmp = load ptr, ptr %tmp4, align 4 ; <ptr> [#uses=1]
84 %scevgep1516 = getelementptr inbounds %struct.attribute_spec, ptr %tmp, i32 %storemerge6.i, i32 0 ; <ptr> [#uses=0]
98 @g = external global i64, align 8
100 define ptr @test3(i1 %arg) {
102 %tmp18.i = load ptr, ptr undef
103 br i1 %arg, label %do.body36.i, label %if.then21.i
109 %ivar38.i = load i64, ptr @g
110 %add.ptr39.sum.i = add i64 %ivar38.i, 8
111 %tmp40.i = getelementptr inbounds i8, ptr %tmp18.i, i64 %add.ptr39.sum.i
112 %tmp41.i = load i64, ptr %tmp40.i
113 br i1 %arg, label %if.then48.i, label %do.body57.i
116 %call54.i = call i32 @foo2()
117 br label %do.body57.i
120 %tmp58.i = load ptr, ptr undef
121 %ivar59.i = load i64, ptr @g
122 %add.ptr65.sum.i = add i64 %ivar59.i, 8
123 %tmp66.i = getelementptr inbounds i8, ptr %tmp58.i, i64 %add.ptr65.sum.i
124 %tmp67.i = load i64, ptr %tmp66.i
132 define i32 @test4() {
137 %P2 = getelementptr i32, ptr %P2, i32 52
138 %Q2 = getelementptr i32, ptr %Q2, i32 52
140 %A = load i32, ptr %Q2
141 br i1 true, label %dead, label %dead2
149 define fastcc i8 @test5(ptr %P) nounwind {
151 %0 = load i8, ptr %P, align 2
153 %Q = getelementptr i8, ptr %P, i32 1
154 %1 = load i8, ptr %Q, align 1
159 ; Test that a GEP in an unreachable block with the following form doesn't crash
162 ; %x = gep %some.type %x, ...
164 %struct.type = type { i64, i32, i32 }
166 define fastcc void @func(i1 %arg) nounwind uwtable ssp align 2 {
168 br label %reachable.bb
173 %gep.val = getelementptr inbounds %struct.type, ptr %gep.val, i64 1
174 br i1 %arg, label %u2.bb, label %u1.bb
177 store i64 -1, ptr %gep.val, align 8
178 br label %unreachable.bb
181 %0 = load i32, ptr undef, align 4
182 %conv.i.i.i.i.i = zext i32 %0 to i64