1; RUN: opt < %s -loop-reduce -S 2 3; Test that SCEV insertpoint's don't get corrupted and cause an 4; invalid instruction to be inserted in a block other than its parent. 5; See http://reviews.llvm.org/D20703 for context. 6define void @test() { 7entry: 8 %bf.load = load i32, i32* null, align 4 9 %bf.clear = lshr i32 %bf.load, 1 10 %div = and i32 %bf.clear, 134217727 11 %sub = add nsw i32 %div, -1 12 %0 = zext i32 %sub to i64 13 br label %while.cond 14 15while.cond: ; preds = %cond.end, %entry 16 %indvars.iv = phi i64 [ %indvars.iv.next, %cond.end ], [ 0, %entry ] 17 %cmp = icmp eq i64 %indvars.iv, %0 18 br i1 %cmp, label %cleanup16, label %while.body 19 20while.body: ; preds = %while.cond 21 %1 = trunc i64 %indvars.iv to i32 22 %mul = shl i32 %1, 1 23 %add = add nuw i32 %mul, 2 24 %cmp3 = icmp ult i32 %add, 0 25 br i1 %cmp3, label %if.end, label %if.then 26 27if.then: ; preds = %while.body 28 unreachable 29 30if.end: ; preds = %while.body 31 br i1 false, label %cond.end, label %cond.true 32 33cond.true: ; preds = %if.end 34 br label %cond.end 35 36cond.end: ; preds = %cond.true, %if.end 37 %add7 = add i32 %1, 1 38 %cmp12 = icmp ugt i32 %add7, %sub 39 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 40 br i1 %cmp12, label %if.then13, label %while.cond 41 42if.then13: ; preds = %cond.end 43 unreachable 44 45cleanup16: ; preds = %while.cond 46 ret void 47} 48