1; RUN: opt -basic-aa -loop-idiom < %s -S | FileCheck %s
2target datalayout = "e-p:64:64:64:32-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"
3
4; CHECK: @.memset_pattern = private unnamed_addr constant [4 x i32] [i32 2, i32 2, i32 2, i32 2], align 16
5
6target triple = "x86_64-apple-darwin10.0.0"
7
8;void test(int *f, unsigned n) {
9;  for (unsigned i = 0; i < 2 * n; i += 2) {
10;    f[i] = 0;
11;    f[i+1] = 0;
12;  }
13;}
14define void @test(i32* %f, i32 %n) nounwind ssp {
15entry:
16  %0 = shl i32 %n, 1
17  %cmp1 = icmp eq i32 %0, 0
18  br i1 %cmp1, label %for.end, label %for.body.preheader
19
20for.body.preheader:                               ; preds = %entry
21  br label %for.body
22
23for.body:                                         ; preds = %for.body.preheader, %for.body
24  %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
25  %arrayidx = getelementptr inbounds i32, i32* %f, i32 %indvars.iv
26  store i32 0, i32* %arrayidx, align 4
27  %1 = or i32 %indvars.iv, 1
28  %arrayidx2 = getelementptr inbounds i32, i32* %f, i32 %1
29  store i32 0, i32* %arrayidx2, align 4
30  %indvars.iv.next = add nuw nsw i32 %indvars.iv, 2
31  %cmp = icmp ult i32 %indvars.iv.next, %0
32  br i1 %cmp, label %for.body, label %for.end.loopexit
33
34for.end.loopexit:                                 ; preds = %for.body
35  br label %for.end
36
37for.end:                                          ; preds = %for.end.loopexit, %entry
38  ret void
39; CHECK-LABEL: @test(
40; CHECK: call void @llvm.memset
41; CHECK-NOT: store
42}
43
44;void test_pattern(int *f, unsigned n) {
45;  for (unsigned i = 0; i < 2 * n; i += 2) {
46;    f[i] = 2;
47;    f[i+1] = 2;
48;  }
49;}
50define void @test_pattern(i32* %f, i32 %n) nounwind ssp {
51entry:
52  %mul = shl i32 %n, 1
53  %cmp1 = icmp eq i32 %mul, 0
54  br i1 %cmp1, label %for.end, label %for.body.preheader
55
56for.body.preheader:                               ; preds = %entry
57  br label %for.body
58
59for.body:                                         ; preds = %for.body.preheader, %for.body
60  %indvars.iv = phi i32 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
61  %arrayidx = getelementptr inbounds i32, i32* %f, i32 %indvars.iv
62  store i32 2, i32* %arrayidx, align 4
63  %x1 = or i32 %indvars.iv, 1
64  %arrayidx2 = getelementptr inbounds i32, i32* %f, i32 %x1
65  store i32 2, i32* %arrayidx2, align 4
66  %indvars.iv.next = add nuw nsw i32 %indvars.iv, 2
67  %cmp = icmp ult i32 %indvars.iv.next, %mul
68  br i1 %cmp, label %for.body, label %for.end.loopexit
69
70for.end.loopexit:                                 ; preds = %for.body
71  br label %for.end
72
73for.end:                                          ; preds = %for.end.loopexit, %entry
74  ret void
75; CHECK-LABEL: @test_pattern(
76; CHECK: call void @memset_pattern16
77; CHECK-NOT: store
78}
79