1; RUN: opt -basic-aa -loop-idiom < %s -S | FileCheck %s 2 3target datalayout = "e-p:32:32:32-p1:64:64:64-p2:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:32-n8:16:32:64" 4target triple = "x86_64-apple-darwin10.0.0" 5 6; Two dimensional nested loop should be promoted to one big memset. 7define void @test10(i8 addrspace(2)* %X) nounwind ssp { 8; CHECK-LABEL: @test10( 9; CHECK: entry: 10; CHECK-NEXT: call void @llvm.memset.p2i8.i16(i8 addrspace(2)* align 1 %X, i8 0, i16 10000, i1 false) 11; CHECK-NOT: store 12; CHECK: ret void 13 14entry: 15 br label %bb.nph 16 17bb.nph: ; preds = %entry, %for.inc10 18 %i.04 = phi i16 [ 0, %entry ], [ %inc12, %for.inc10 ] 19 br label %for.body5 20 21for.body5: ; preds = %for.body5, %bb.nph 22 %j.02 = phi i16 [ 0, %bb.nph ], [ %inc, %for.body5 ] 23 %mul = mul nsw i16 %i.04, 100 24 %add = add nsw i16 %j.02, %mul 25 %arrayidx = getelementptr inbounds i8, i8 addrspace(2)* %X, i16 %add 26 store i8 0, i8 addrspace(2)* %arrayidx, align 1 27 %inc = add nsw i16 %j.02, 1 28 %cmp4 = icmp eq i16 %inc, 100 29 br i1 %cmp4, label %for.inc10, label %for.body5 30 31for.inc10: ; preds = %for.body5 32 %inc12 = add nsw i16 %i.04, 1 33 %cmp = icmp eq i16 %inc12, 100 34 br i1 %cmp, label %for.end13, label %bb.nph 35 36for.end13: ; preds = %for.inc10 37 ret void 38} 39 40define void @test11_pattern(i32 addrspace(2)* nocapture %P) nounwind ssp { 41; CHECK-LABEL: @test11_pattern( 42; CHECK-NOT: memset_pattern 43entry: 44 br label %for.body 45 46for.body: ; preds = %entry, %for.body 47 %indvar = phi i64 [ 0, %entry ], [ %indvar.next, %for.body ] 48 %arrayidx = getelementptr i32, i32 addrspace(2)* %P, i64 %indvar 49 store i32 1, i32 addrspace(2)* %arrayidx, align 4 50 %indvar.next = add i64 %indvar, 1 51 %exitcond = icmp eq i64 %indvar.next, 10000 52 br i1 %exitcond, label %for.end, label %for.body 53 54for.end: ; preds = %for.body 55 ret void 56} 57 58; PR9815 - This is a partial overlap case that cannot be safely transformed 59; into a memcpy. 60@g_50 = addrspace(2) global [7 x i32] [i32 0, i32 0, i32 0, i32 0, i32 1, i32 0, i32 0], align 16 61 62 63define i32 @test14() nounwind { 64; CHECK-LABEL: @test14( 65; CHECK: for.body: 66; CHECK: load i32 67; CHECK: store i32 68; CHECK: br i1 %cmp 69 70entry: 71 br label %for.body 72 73for.body: ; preds = %for.inc, %for.body.lr.ph 74 %tmp5 = phi i32 [ %inc, %for.body ], [ 0, %entry ] 75 %add = add nsw i32 %tmp5, 4 76 %idxprom = sext i32 %add to i64 77 %arrayidx = getelementptr inbounds [7 x i32], [7 x i32] addrspace(2)* @g_50, i32 0, i64 %idxprom 78 %tmp2 = load i32, i32 addrspace(2)* %arrayidx, align 4 79 %add4 = add nsw i32 %tmp5, 5 80 %idxprom5 = sext i32 %add4 to i64 81 %arrayidx6 = getelementptr inbounds [7 x i32], [7 x i32] addrspace(2)* @g_50, i32 0, i64 %idxprom5 82 store i32 %tmp2, i32 addrspace(2)* %arrayidx6, align 4 83 %inc = add nsw i32 %tmp5, 1 84 %cmp = icmp slt i32 %inc, 2 85 br i1 %cmp, label %for.body, label %for.end 86 87for.end: ; preds = %for.inc 88 %tmp8 = load i32, i32 addrspace(2)* getelementptr inbounds ([7 x i32], [7 x i32] addrspace(2)* @g_50, i32 0, i64 6), align 4 89 ret i32 %tmp8 90} 91 92