1*9880d681SAndroid Build Coastguard Worker; RUN: opt -loop-reduce -S < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker; 3*9880d681SAndroid Build Coastguard Worker; <rdar://problem/11049788> Segmentation fault: 11 in LoopStrengthReduce 4*9880d681SAndroid Build Coastguard Worker 5*9880d681SAndroid Build Coastguard Workertarget 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*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-apple-darwin10.0.0" 7*9880d681SAndroid Build Coastguard Worker 8*9880d681SAndroid Build Coastguard Worker; IVUsers should not consider tmp128 a valid user because it is not in a 9*9880d681SAndroid Build Coastguard Worker; simplified loop nest. 10*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @nopreheader( 11*9880d681SAndroid Build Coastguard Worker; CHECK: for.cond: 12*9880d681SAndroid Build Coastguard Worker; CHECK: %tmp128 = add i64 %0, %indvar65 13*9880d681SAndroid Build Coastguard Workerdefine void @nopreheader(i8* %cmd) nounwind ssp { 14*9880d681SAndroid Build Coastguard Workerentry: 15*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond] 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Workerwhile.cond: ; preds = %while.body, %entry 18*9880d681SAndroid Build Coastguard Worker %0 = phi i64 [ %indvar.next48, %while.body ], [ 0, %entry ] 19*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.end, label %while.body] 20*9880d681SAndroid Build Coastguard Worker 21*9880d681SAndroid Build Coastguard Workerwhile.body: ; preds = %lor.rhs, %lor.lhs.false17, %lor.lhs.false11, %lor.lhs.false, %land.rhs 22*9880d681SAndroid Build Coastguard Worker %indvar.next48 = add i64 %0, 1 23*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond] 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Workerwhile.end: ; preds = %lor.rhs, %while.cond 26*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %if.end152] 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Workerif.end152: ; preds = %lor.lhs.false144, %if.end110 29*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %lor.lhs.false184, label %for.cond] 30*9880d681SAndroid Build Coastguard Worker 31*9880d681SAndroid Build Coastguard Workerlor.lhs.false184: ; preds = %lor.lhs.false177 32*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %return, label %for.cond] 33*9880d681SAndroid Build Coastguard Worker 34*9880d681SAndroid Build Coastguard Workerfor.cond: ; preds = %for.inc, %lor.lhs.false184, %if.end152 35*9880d681SAndroid Build Coastguard Worker %indvar65 = phi i64 [ %indvar.next66, %for.inc ], [ 0, %lor.lhs.false184 ], [ 0, %if.end152 ] 36*9880d681SAndroid Build Coastguard Worker %tmp128 = add i64 %0, %indvar65 37*9880d681SAndroid Build Coastguard Worker %s.4 = getelementptr i8, i8* %cmd, i64 %tmp128 38*9880d681SAndroid Build Coastguard Worker %tmp195 = load i8, i8* %s.4, align 1 39*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %return, label %land.rhs198] 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Workerland.rhs198: ; preds = %for.cond 42*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %return, label %for.inc] 43*9880d681SAndroid Build Coastguard Worker 44*9880d681SAndroid Build Coastguard Workerfor.inc: ; preds = %lor.rhs234, %land.lhs.true228, %land.lhs.true216, %land.lhs.true204 45*9880d681SAndroid Build Coastguard Worker %indvar.next66 = add i64 %indvar65, 1 46*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %for.cond] 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Workerreturn: ; preds = %if.end677, %doshell, %if.then96 49*9880d681SAndroid Build Coastguard Worker ret void 50*9880d681SAndroid Build Coastguard Worker} 51*9880d681SAndroid Build Coastguard Worker 52*9880d681SAndroid Build Coastguard Worker; Another case with a dominating loop that does not contain the IV 53*9880d681SAndroid Build Coastguard Worker; User. Just make sure it doesn't assert. 54*9880d681SAndroid Build Coastguard Workerdefine void @nopreheader2() nounwind ssp { 55*9880d681SAndroid Build Coastguard Workerentry: 56*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond, label %return] 57*9880d681SAndroid Build Coastguard Worker 58*9880d681SAndroid Build Coastguard Workerwhile.cond: ; preds = %while.cond.backedge, %entry 59*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond.backedge, label %lor.rhs] 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Workerlor.rhs: ; preds = %while.cond 62*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond.backedge, label %while.end] 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Workerwhile.cond.backedge: ; preds = %lor.rhs, %while.cond 65*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond] 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard Workerwhile.end: ; preds = %lor.rhs 68*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %if.then18, label %return] 69*9880d681SAndroid Build Coastguard Worker 70*9880d681SAndroid Build Coastguard Workerif.then18: ; preds = %while.end 71*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %if.end35, label %lor.lhs.false] 72*9880d681SAndroid Build Coastguard Worker 73*9880d681SAndroid Build Coastguard Workerlor.lhs.false: ; preds = %if.then18 74*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %if.end35, label %return] 75*9880d681SAndroid Build Coastguard Worker 76*9880d681SAndroid Build Coastguard Workerif.end35: ; preds = %lor.lhs.false, %if.then18 77*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond36] 78*9880d681SAndroid Build Coastguard Worker 79*9880d681SAndroid Build Coastguard Workerwhile.cond36: ; preds = %while.body49, %if.end35 80*9880d681SAndroid Build Coastguard Worker %0 = phi i64 [ %indvar.next13, %while.body49 ], [ 0, %if.end35 ] 81*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.body49, label %lor.rhs42] 82*9880d681SAndroid Build Coastguard Worker 83*9880d681SAndroid Build Coastguard Workerlor.rhs42: ; preds = %while.cond36 84*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.body49, label %while.end52] 85*9880d681SAndroid Build Coastguard Worker 86*9880d681SAndroid Build Coastguard Workerwhile.body49: ; preds = %lor.rhs42, %while.cond36 87*9880d681SAndroid Build Coastguard Worker %indvar.next13 = add i64 %0, 1 88*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond36] 89*9880d681SAndroid Build Coastguard Worker 90*9880d681SAndroid Build Coastguard Workerwhile.end52: ; preds = %lor.rhs42 91*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %land.lhs.true, label %return] 92*9880d681SAndroid Build Coastguard Worker 93*9880d681SAndroid Build Coastguard Workerland.lhs.true: ; preds = %while.end52 94*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond66.preheader, label %return] 95*9880d681SAndroid Build Coastguard Worker 96*9880d681SAndroid Build Coastguard Workerwhile.cond66.preheader: ; preds = %land.lhs.true 97*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond66] 98*9880d681SAndroid Build Coastguard Worker 99*9880d681SAndroid Build Coastguard Workerwhile.cond66: ; preds = %while.body77, %while.cond66.preheader 100*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %land.rhs, label %while.cond81.preheader] 101*9880d681SAndroid Build Coastguard Worker 102*9880d681SAndroid Build Coastguard Workerland.rhs: ; preds = %while.cond66 103*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.body77, label %while.cond81.preheader] 104*9880d681SAndroid Build Coastguard Worker 105*9880d681SAndroid Build Coastguard Workerwhile.cond81.preheader: ; preds = %land.rhs, %while.cond66 106*9880d681SAndroid Build Coastguard Worker %tmp45 = add i64 undef, %0 107*9880d681SAndroid Build Coastguard Worker %tmp46 = add i64 %tmp45, undef 108*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond81] 109*9880d681SAndroid Build Coastguard Worker 110*9880d681SAndroid Build Coastguard Workerwhile.body77: ; preds = %land.rhs 111*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond66] 112*9880d681SAndroid Build Coastguard Worker 113*9880d681SAndroid Build Coastguard Workerwhile.cond81: ; preds = %while.body94, %while.cond81.preheader 114*9880d681SAndroid Build Coastguard Worker %tmp25 = add i64 %tmp46, undef 115*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.body94, label %lor.rhs87] 116*9880d681SAndroid Build Coastguard Worker 117*9880d681SAndroid Build Coastguard Workerlor.rhs87: ; preds = %while.cond81 118*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.body94, label %return] 119*9880d681SAndroid Build Coastguard Worker 120*9880d681SAndroid Build Coastguard Workerwhile.body94: ; preds = %lor.rhs87, %while.cond81 121*9880d681SAndroid Build Coastguard Worker indirectbr i8* undef, [label %while.cond81] 122*9880d681SAndroid Build Coastguard Worker 123*9880d681SAndroid Build Coastguard Workerreturn: ; preds = %if.end216, %land.lhs.true183, %land.lhs.true, %while.end52, %lor.lhs.false, %while.end, %entry 124*9880d681SAndroid Build Coastguard Worker ret void 125*9880d681SAndroid Build Coastguard Worker} 126*9880d681SAndroid Build Coastguard Worker 127*9880d681SAndroid Build Coastguard Worker; Test a phi operand IV User dominated by a no-preheader loop. 128*9880d681SAndroid Build Coastguard Workerdefine void @nopreheader3() nounwind uwtable ssp align 2 { 129*9880d681SAndroid Build Coastguard Workerentry: 130*9880d681SAndroid Build Coastguard Worker indirectbr i8* blockaddress(@nopreheader3, %if.end10), [label %if.end22, label %if.end10] 131*9880d681SAndroid Build Coastguard Worker 132*9880d681SAndroid Build Coastguard Workerif.end10: ; preds = %entry 133*9880d681SAndroid Build Coastguard Worker indirectbr i8* blockaddress(@nopreheader3, %if.end6.i), [label %if.end22, label %if.end6.i] 134*9880d681SAndroid Build Coastguard Worker 135*9880d681SAndroid Build Coastguard Workerif.end6.i: ; preds = %if.end10 136*9880d681SAndroid Build Coastguard Worker indirectbr i8* blockaddress(@nopreheader3, %while.cond2.preheader.i.i), [label %if.then12, label %while.cond2.preheader.i.i] 137*9880d681SAndroid Build Coastguard Worker 138*9880d681SAndroid Build Coastguard Workerwhile.cond2.preheader.i.i: ; preds = %while.end.i18.i, %if.end6.i 139*9880d681SAndroid Build Coastguard Worker indirectbr i8* blockaddress(@nopreheader3, %while.cond2.i.i), [label %while.cond2.i.i] 140*9880d681SAndroid Build Coastguard Worker 141*9880d681SAndroid Build Coastguard Workerwhile.cond2.i.i: ; preds = %while.cond2.i.i, %while.cond2.preheader.i.i 142*9880d681SAndroid Build Coastguard Worker %i1.1.i14.i = phi i32 [ %add.i15.i, %while.cond2.i.i ], [ undef, %while.cond2.preheader.i.i ] 143*9880d681SAndroid Build Coastguard Worker %add.i15.i = add nsw i32 %i1.1.i14.i, undef 144*9880d681SAndroid Build Coastguard Worker indirectbr i8* blockaddress(@nopreheader3, %while.end.i18.i), [label %while.cond2.i.i, label %while.end.i18.i] 145*9880d681SAndroid Build Coastguard Worker 146*9880d681SAndroid Build Coastguard Workerwhile.end.i18.i: ; preds = %while.cond2.i.i 147*9880d681SAndroid Build Coastguard Worker indirectbr i8* blockaddress(@nopreheader3, %while.cond2.preheader.i.i), [label %if.then12, label %while.cond2.preheader.i.i] 148*9880d681SAndroid Build Coastguard Worker 149*9880d681SAndroid Build Coastguard Workerif.then12: ; preds = %while.end.i18.i, %if.end6.i 150*9880d681SAndroid Build Coastguard Worker %i1.0.lcssa.i.i = phi i32 [ undef, %if.end6.i ], [ %i1.1.i14.i, %while.end.i18.i ] 151*9880d681SAndroid Build Coastguard Worker indirectbr i8* blockaddress(@nopreheader3, %if.end22), [label %if.end22] 152*9880d681SAndroid Build Coastguard Worker 153*9880d681SAndroid Build Coastguard Workerif.end22: ; preds = %if.then12, %if.end10, %entry 154*9880d681SAndroid Build Coastguard Worker ret void 155*9880d681SAndroid Build Coastguard Worker} 156