1 ; RUN: opt -basic-aa -loop-idiom < %s -S | FileCheck %s
3 target 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"
4 target triple = "x86_64-apple-darwin10.0.0"
6 ; Two dimensional nested loop should be promoted to one big memset.
7 define void @test10(i8 addrspace(2)* %X) nounwind ssp {
8 ; CHECK-LABEL: @test10(
10 ; CHECK-NEXT: call void @llvm.memset.p2i8.i16(i8 addrspace(2)* align 1 %X, i8 0, i16 10000, i1 false)
17 bb.nph: ; preds = %entry, %for.inc10
18 %i.04 = phi i16 [ 0, %entry ], [ %inc12, %for.inc10 ]
21 for.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
31 for.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
36 for.end13: ; preds = %for.inc10
40 define void @test11_pattern(i32 addrspace(2)* nocapture %P) nounwind ssp {
41 ; CHECK-LABEL: @test11_pattern(
42 ; CHECK-NOT: memset_pattern
46 for.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
54 for.end: ; preds = %for.body
58 ; PR9815 - This is a partial overlap case that cannot be safely transformed
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
63 define i32 @test14() nounwind {
64 ; CHECK-LABEL: @test14(
73 for.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
87 for.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