1; RUN: opt < %s  -cost-model -analyze -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s
2
3target 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-S128"
4target triple = "x86_64-apple-macosx10.8.0"
5
6define i32 @foo(i32* noalias nocapture %A, i32* noalias nocapture %B, i32 %start, i32 %end) nounwind uwtable ssp {
7entry:
8  ;CHECK: cost of 1 {{.*}} icmp
9  %cmp7 = icmp slt i32 %start, %end
10  br i1 %cmp7, label %for.body.lr.ph, label %for.end
11
12for.body.lr.ph:                                   ; preds = %entry
13  ;CHECK: cost of 1 {{.*}} sext
14  %0 = sext i32 %start to i64
15  %1 = sub i32 %end, %start
16  %2 = zext i32 %1 to i64
17  %end.idx = add i64 %2, %0
18  ;CHECK: cost of 1 {{.*}} add
19  %n.vec = and i64 %2, 4294967288
20  %end.idx.rnd.down = add i64 %n.vec, %0
21  ;CHECK: cost of 1 {{.*}} icmp
22  %cmp.zero = icmp eq i64 %n.vec, 0
23  br i1 %cmp.zero, label %middle.block, label %vector.body
24
25vector.body:                                      ; preds = %for.body.lr.ph, %vector.body
26  %index = phi i64 [ %index.next, %vector.body ], [ %0, %for.body.lr.ph ]
27  %3 = add i64 %index, 2
28  %4 = getelementptr inbounds i32* %B, i64 %3
29  ;CHECK: cost of 0 {{.*}} bitcast
30  %5 = bitcast i32* %4 to <8 x i32>*
31  ;CHECK: cost of 1 {{.*}} load
32  %6 = load <8 x i32>* %5, align 4
33  ;CHECK: cost of 4 {{.*}} mul
34  %7 = mul nsw <8 x i32> %6, <i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5>
35  %8 = getelementptr inbounds i32* %A, i64 %index
36  %9 = bitcast i32* %8 to <8 x i32>*
37  %10 = load <8 x i32>* %9, align 4
38  ;CHECK: cost of 4 {{.*}} add
39  %11 = add nsw <8 x i32> %10, %7
40  ;CHECK: cost of 1 {{.*}} store
41  store <8 x i32> %11, <8 x i32>* %9, align 4
42  %index.next = add i64 %index, 8
43  %12 = icmp eq i64 %index.next, %end.idx.rnd.down
44  ;CHECK: cost of 0 {{.*}} br
45  br i1 %12, label %middle.block, label %vector.body
46
47middle.block:                                     ; preds = %vector.body, %for.body.lr.ph
48  %cmp.n = icmp eq i64 %end.idx, %end.idx.rnd.down
49  br i1 %cmp.n, label %for.end, label %for.body
50
51for.body:                                         ; preds = %middle.block, %for.body
52  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ %end.idx.rnd.down, %middle.block ]
53  %13 = add nsw i64 %indvars.iv, 2
54  %arrayidx = getelementptr inbounds i32* %B, i64 %13
55  ;CHECK: cost of 1 {{.*}} load
56  %14 = load i32* %arrayidx, align 4, !tbaa !0
57  ;CHECK: cost of 1 {{.*}} mul
58  %mul = mul nsw i32 %14, 5
59  %arrayidx2 = getelementptr inbounds i32* %A, i64 %indvars.iv
60  ;CHECK: cost of 1 {{.*}} load
61  %15 = load i32* %arrayidx2, align 4, !tbaa !0
62  %add3 = add nsw i32 %15, %mul
63  store i32 %add3, i32* %arrayidx2, align 4, !tbaa !0
64  %indvars.iv.next = add i64 %indvars.iv, 1
65  ;CHECK: cost of 0 {{.*}} trunc
66  %16 = trunc i64 %indvars.iv.next to i32
67  %cmp = icmp slt i32 %16, %end
68  ;CHECK: cost of 0 {{.*}} br
69  br i1 %cmp, label %for.body, label %for.end
70
71for.end:                                          ; preds = %middle.block, %for.body, %entry
72  ;CHECK: cost of 0 {{.*}} ret
73  ret i32 undef
74}
75
76!0 = metadata !{metadata !"int", metadata !1}
77!1 = metadata !{metadata !"omnipotent char", metadata !2}
78!2 = metadata !{metadata !"Simple C/C++ TBAA"}
79