1*f4a2713aSLionel Sambuc; RUN: opt -gvn -disable-output < %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc; PR5631 4*f4a2713aSLionel Sambuc 5*f4a2713aSLionel Sambuctarget 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*f4a2713aSLionel Sambuctarget triple = "x86_64-apple-darwin10.0" 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambucdefine i32* @test1(i8* %name, i32 %namelen, i32* %o, i32 %expected_type) nounwind ssp { 9*f4a2713aSLionel Sambucentry: 10*f4a2713aSLionel Sambuc br i1 undef, label %if.end13, label %while.body.preheader 11*f4a2713aSLionel Sambuc 12*f4a2713aSLionel Sambuc 13*f4a2713aSLionel Sambucif.end13: ; preds = %if.then6 14*f4a2713aSLionel Sambuc br label %while.body.preheader 15*f4a2713aSLionel Sambuc 16*f4a2713aSLionel Sambucwhile.body.preheader: ; preds = %if.end13, %if.end 17*f4a2713aSLionel Sambuc br label %while.body 18*f4a2713aSLionel Sambuc 19*f4a2713aSLionel Sambucwhile.body: ; preds = %while.body.backedge, %while.body.preheader 20*f4a2713aSLionel Sambuc %o.addr.0 = phi i32* [ undef, %while.body.preheader ], [ %o.addr.0.be, %while.body.backedge ] ; <i32*> [#uses=2] 21*f4a2713aSLionel Sambuc br i1 false, label %return.loopexit, label %lor.lhs.false 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuclor.lhs.false: ; preds = %while.body 24*f4a2713aSLionel Sambuc %tmp20 = bitcast i32* %o.addr.0 to i32* ; <i32*> [#uses=1] 25*f4a2713aSLionel Sambuc %tmp22 = load i32* %tmp20 ; <i32> [#uses=0] 26*f4a2713aSLionel Sambuc br i1 undef, label %land.lhs.true24, label %if.end31 27*f4a2713aSLionel Sambuc 28*f4a2713aSLionel Sambucland.lhs.true24: ; preds = %lor.lhs.false 29*f4a2713aSLionel Sambuc %call28 = call i32* @parse_object(i8* undef) nounwind ; <i32*> [#uses=0] 30*f4a2713aSLionel Sambuc br i1 undef, label %return.loopexit, label %if.end31 31*f4a2713aSLionel Sambuc 32*f4a2713aSLionel Sambucif.end31: ; preds = %land.lhs.true24, %lor.lhs.false 33*f4a2713aSLionel Sambuc br i1 undef, label %return.loopexit, label %if.end41 34*f4a2713aSLionel Sambuc 35*f4a2713aSLionel Sambucif.end41: ; preds = %if.end31 36*f4a2713aSLionel Sambuc %tmp43 = bitcast i32* %o.addr.0 to i32* ; <i32*> [#uses=1] 37*f4a2713aSLionel Sambuc %tmp45 = load i32* %tmp43 ; <i32> [#uses=0] 38*f4a2713aSLionel Sambuc br i1 undef, label %if.then50, label %if.else 39*f4a2713aSLionel Sambuc 40*f4a2713aSLionel Sambucif.then50: ; preds = %if.end41 41*f4a2713aSLionel Sambuc %tmp53 = load i32** undef ; <i32*> [#uses=1] 42*f4a2713aSLionel Sambuc br label %while.body.backedge 43*f4a2713aSLionel Sambuc 44*f4a2713aSLionel Sambucif.else: ; preds = %if.end41 45*f4a2713aSLionel Sambuc br i1 undef, label %if.then62, label %if.else67 46*f4a2713aSLionel Sambuc 47*f4a2713aSLionel Sambucif.then62: ; preds = %if.else 48*f4a2713aSLionel Sambuc br label %while.body.backedge 49*f4a2713aSLionel Sambuc 50*f4a2713aSLionel Sambucwhile.body.backedge: ; preds = %if.then62, %if.then50 51*f4a2713aSLionel Sambuc %o.addr.0.be = phi i32* [ %tmp53, %if.then50 ], [ undef, %if.then62 ] ; <i32*> [#uses=1] 52*f4a2713aSLionel Sambuc br label %while.body 53*f4a2713aSLionel Sambuc 54*f4a2713aSLionel Sambucif.else67: ; preds = %if.else 55*f4a2713aSLionel Sambuc ret i32* null 56*f4a2713aSLionel Sambuc 57*f4a2713aSLionel Sambucreturn.loopexit: ; preds = %if.end31, %land.lhs.true24, %while.body 58*f4a2713aSLionel Sambuc ret i32* undef 59*f4a2713aSLionel Sambuc} 60*f4a2713aSLionel Sambuc 61*f4a2713aSLionel Sambucdeclare i32* @parse_object(i8*) 62*f4a2713aSLionel Sambuc 63*f4a2713aSLionel Sambuc 64*f4a2713aSLionel Sambuc 65*f4a2713aSLionel Sambuc 66*f4a2713aSLionel Sambuc 67*f4a2713aSLionel Sambuc 68*f4a2713aSLionel Sambuc%struct.attribute_spec = type { i8*, i32, i32, i8, i8, i8 } 69*f4a2713aSLionel Sambuc 70*f4a2713aSLionel Sambuc@attribute_tables = external global [4 x %struct.attribute_spec*] ; <[4 x %struct.attribute_spec*]*> [#uses=2] 71*f4a2713aSLionel Sambuc 72*f4a2713aSLionel Sambucdefine void @test2() nounwind { 73*f4a2713aSLionel Sambucentry: 74*f4a2713aSLionel Sambuc br label %bb69.i 75*f4a2713aSLionel Sambuc 76*f4a2713aSLionel Sambucbb69.i: ; preds = %bb57.i.preheader 77*f4a2713aSLionel Sambuc %tmp4 = getelementptr inbounds [4 x %struct.attribute_spec*]* @attribute_tables, i32 0, i32 undef ; <%struct.attribute_spec**> [#uses=1] 78*f4a2713aSLionel Sambuc %tmp3 = load %struct.attribute_spec** %tmp4, align 4 ; <%struct.attribute_spec*> [#uses=1] 79*f4a2713aSLionel Sambuc br label %bb65.i 80*f4a2713aSLionel Sambuc 81*f4a2713aSLionel Sambucbb65.i: ; preds = %bb65.i.preheader, %bb64.i 82*f4a2713aSLionel Sambuc %storemerge6.i = phi i32 [ 1, %bb64.i ], [ 0, %bb69.i ] ; <i32> [#uses=3] 83*f4a2713aSLionel Sambuc %scevgep14 = getelementptr inbounds %struct.attribute_spec* %tmp3, i32 %storemerge6.i, i32 0 ; <i8**> [#uses=1] 84*f4a2713aSLionel Sambuc %tmp2 = load i8** %scevgep14, align 4 ; <i8*> [#uses=0] 85*f4a2713aSLionel Sambuc %tmp = load %struct.attribute_spec** %tmp4, align 4 ; <%struct.attribute_spec*> [#uses=1] 86*f4a2713aSLionel Sambuc %scevgep1516 = getelementptr inbounds %struct.attribute_spec* %tmp, i32 %storemerge6.i, i32 0 ; <i8**> [#uses=0] 87*f4a2713aSLionel Sambuc unreachable 88*f4a2713aSLionel Sambuc 89*f4a2713aSLionel Sambucbb64.i: ; Unreachable 90*f4a2713aSLionel Sambuc br label %bb65.i 91*f4a2713aSLionel Sambuc 92*f4a2713aSLionel Sambucbb66.i: ; Unreachable 93*f4a2713aSLionel Sambuc br label %bb69.i 94*f4a2713aSLionel Sambuc} 95*f4a2713aSLionel Sambuc 96*f4a2713aSLionel Sambuc 97*f4a2713aSLionel Sambuc 98*f4a2713aSLionel Sambuc; rdar://7438974 99*f4a2713aSLionel Sambuc 100*f4a2713aSLionel Sambuc@g = external global i64, align 8 101*f4a2713aSLionel Sambuc 102*f4a2713aSLionel Sambucdefine i32* @test3() { 103*f4a2713aSLionel Sambucdo.end17.i: 104*f4a2713aSLionel Sambuc %tmp18.i = load i7** undef 105*f4a2713aSLionel Sambuc %tmp1 = bitcast i7* %tmp18.i to i8* 106*f4a2713aSLionel Sambuc br i1 undef, label %do.body36.i, label %if.then21.i 107*f4a2713aSLionel Sambuc 108*f4a2713aSLionel Sambucif.then21.i: 109*f4a2713aSLionel Sambuc %tmp2 = bitcast i7* %tmp18.i to i8* 110*f4a2713aSLionel Sambuc ret i32* undef 111*f4a2713aSLionel Sambuc 112*f4a2713aSLionel Sambucdo.body36.i: 113*f4a2713aSLionel Sambuc %ivar38.i = load i64* @g 114*f4a2713aSLionel Sambuc %tmp3 = bitcast i7* %tmp18.i to i8* 115*f4a2713aSLionel Sambuc %add.ptr39.sum.i = add i64 %ivar38.i, 8 116*f4a2713aSLionel Sambuc %tmp40.i = getelementptr inbounds i8* %tmp3, i64 %add.ptr39.sum.i 117*f4a2713aSLionel Sambuc %tmp4 = bitcast i8* %tmp40.i to i64* 118*f4a2713aSLionel Sambuc %tmp41.i = load i64* %tmp4 119*f4a2713aSLionel Sambuc br i1 undef, label %if.then48.i, label %do.body57.i 120*f4a2713aSLionel Sambuc 121*f4a2713aSLionel Sambucif.then48.i: 122*f4a2713aSLionel Sambuc %call54.i = call i32 @foo2() 123*f4a2713aSLionel Sambuc br label %do.body57.i 124*f4a2713aSLionel Sambuc 125*f4a2713aSLionel Sambucdo.body57.i: 126*f4a2713aSLionel Sambuc %tmp58.i = load i7** undef 127*f4a2713aSLionel Sambuc %ivar59.i = load i64* @g 128*f4a2713aSLionel Sambuc %tmp5 = bitcast i7* %tmp58.i to i8* 129*f4a2713aSLionel Sambuc %add.ptr65.sum.i = add i64 %ivar59.i, 8 130*f4a2713aSLionel Sambuc %tmp66.i = getelementptr inbounds i8* %tmp5, i64 %add.ptr65.sum.i 131*f4a2713aSLionel Sambuc %tmp6 = bitcast i8* %tmp66.i to i64* 132*f4a2713aSLionel Sambuc %tmp67.i = load i64* %tmp6 133*f4a2713aSLionel Sambuc ret i32* undef 134*f4a2713aSLionel Sambuc} 135*f4a2713aSLionel Sambuc 136*f4a2713aSLionel Sambucdeclare i32 @foo2() 137*f4a2713aSLionel Sambuc 138*f4a2713aSLionel Sambuc 139*f4a2713aSLionel Sambuc 140*f4a2713aSLionel Sambucdefine i32 @test4() { 141*f4a2713aSLionel Sambucentry: 142*f4a2713aSLionel Sambuc ret i32 0 143*f4a2713aSLionel Sambuc 144*f4a2713aSLionel Sambucdead: 145*f4a2713aSLionel Sambuc %P2 = getelementptr i32 *%P2, i32 52 146*f4a2713aSLionel Sambuc %Q2 = getelementptr i32 *%Q2, i32 52 147*f4a2713aSLionel Sambuc store i32 4, i32* %P2 148*f4a2713aSLionel Sambuc %A = load i32* %Q2 149*f4a2713aSLionel Sambuc br i1 true, label %dead, label %dead2 150*f4a2713aSLionel Sambuc 151*f4a2713aSLionel Sambucdead2: 152*f4a2713aSLionel Sambuc ret i32 %A 153*f4a2713aSLionel Sambuc} 154*f4a2713aSLionel Sambuc 155*f4a2713aSLionel Sambuc 156*f4a2713aSLionel Sambuc; PR9841 157*f4a2713aSLionel Sambucdefine fastcc i8 @test5(i8* %P) nounwind { 158*f4a2713aSLionel Sambucentry: 159*f4a2713aSLionel Sambuc %0 = load i8* %P, align 2 160*f4a2713aSLionel Sambuc 161*f4a2713aSLionel Sambuc %Q = getelementptr i8* %P, i32 1 162*f4a2713aSLionel Sambuc %1 = load i8* %Q, align 1 163*f4a2713aSLionel Sambuc ret i8 %1 164*f4a2713aSLionel Sambuc} 165*f4a2713aSLionel Sambuc 166*f4a2713aSLionel Sambuc 167*f4a2713aSLionel Sambuc; Test that a GEP in an unreachable block with the following form doesn't crash 168*f4a2713aSLionel Sambuc; GVN: 169*f4a2713aSLionel Sambuc; 170*f4a2713aSLionel Sambuc; %x = gep %some.type %x, ... 171*f4a2713aSLionel Sambuc 172*f4a2713aSLionel Sambuc%struct.type = type { i64, i32, i32 } 173*f4a2713aSLionel Sambuc 174*f4a2713aSLionel Sambucdefine fastcc void @func() nounwind uwtable ssp align 2 { 175*f4a2713aSLionel Sambucentry: 176*f4a2713aSLionel Sambuc br label %reachable.bb 177*f4a2713aSLionel Sambuc 178*f4a2713aSLionel Sambuc;; Unreachable code. 179*f4a2713aSLionel Sambuc 180*f4a2713aSLionel Sambucunreachable.bb: 181*f4a2713aSLionel Sambuc %gep.val = getelementptr inbounds %struct.type* %gep.val, i64 1 182*f4a2713aSLionel Sambuc br i1 undef, label %u2.bb, label %u1.bb 183*f4a2713aSLionel Sambuc 184*f4a2713aSLionel Sambucu1.bb: 185*f4a2713aSLionel Sambuc %tmp1 = getelementptr inbounds %struct.type* %gep.val, i64 0, i32 0 186*f4a2713aSLionel Sambuc store i64 -1, i64* %tmp1, align 8 187*f4a2713aSLionel Sambuc br label %unreachable.bb 188*f4a2713aSLionel Sambuc 189*f4a2713aSLionel Sambucu2.bb: 190*f4a2713aSLionel Sambuc %0 = load i32* undef, align 4 191*f4a2713aSLionel Sambuc %conv.i.i.i.i.i = zext i32 %0 to i64 192*f4a2713aSLionel Sambuc br label %u2.bb 193*f4a2713aSLionel Sambuc 194*f4a2713aSLionel Sambuc;; Reachable code. 195*f4a2713aSLionel Sambuc 196*f4a2713aSLionel Sambucreachable.bb: 197*f4a2713aSLionel Sambuc br label %r1.bb 198*f4a2713aSLionel Sambuc 199*f4a2713aSLionel Sambucr1.bb: 200*f4a2713aSLionel Sambuc br label %u2.bb 201*f4a2713aSLionel Sambuc} 202