OSDN Git Service

Costmodel: Add support for horizontal vector reductions
[android-x86/external-llvm.git] / test / Analysis / CostModel / X86 / reduction.ll
1 ; RUN: opt < %s -cost-model -costmodel-reduxcost=true -analyze -mcpu=core2 -mtriple=x86_64-apple-darwin | FileCheck %s
2
3 define fastcc float @reduction_cost_float(<4 x float> %rdx) {
4   %rdx.shuf = shufflevector <4 x float> %rdx, <4 x float> undef, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
5   %bin.rdx = fadd <4 x float> %rdx, %rdx.shuf
6   %rdx.shuf7 = shufflevector <4 x float> %bin.rdx, <4 x float> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
7   %bin.rdx8 = fadd <4 x float> %bin.rdx, %rdx.shuf7
8
9 ; Check that we recognize the tree starting at the extractelement as a
10 ; reduction.
11 ; CHECK-LABEL: reduction_cost
12 ; CHECK:  cost of 9 {{.*}} extractelement
13
14   %r = extractelement <4 x float> %bin.rdx8, i32 0
15   ret float %r
16 }
17
18 define fastcc i32 @reduction_cost_int(<8 x i32> %rdx) {
19   %rdx.shuf = shufflevector <8 x i32> %rdx, <8 x i32> undef,
20    <8 x i32> <i32 4    , i32     5, i32     6, i32     7,
21               i32 undef, i32 undef, i32 undef, i32 undef>
22   %bin.rdx = add <8 x i32> %rdx, %rdx.shuf
23   %rdx.shuf.2 = shufflevector <8 x i32> %bin.rdx, <8 x i32> undef,
24    <8 x i32> <i32 2    , i32 3,     i32 undef, i32 undef,
25               i32 undef, i32 undef, i32 undef, i32 undef>
26   %bin.rdx.2 = add <8 x i32> %bin.rdx, %rdx.shuf.2
27   %rdx.shuf.3 = shufflevector <8 x i32> %bin.rdx.2, <8 x i32> undef,
28    <8 x i32> <i32 1    , i32 undef, i32 undef, i32 undef,
29               i32 undef, i32 undef, i32 undef, i32 undef>
30   %bin.rdx.3 = add <8 x i32> %bin.rdx.2, %rdx.shuf.3
31
32 ; CHECK-LABEL: reduction_cost_int
33 ; CHECK:  cost of 23 {{.*}} extractelement
34
35   %r = extractelement <8 x i32> %bin.rdx.3, i32 0
36   ret i32 %r
37 }
38
39 define fastcc float @pairwise_hadd(<4 x float> %rdx, float %f1) {
40   %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef,
41         <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef>
42   %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef,
43         <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
44   %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.0, %rdx.shuf.0.1
45   %rdx.shuf.1.0 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
46         <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
47   %rdx.shuf.1.1 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
48         <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
49   %bin.rdx.1 = fadd <4 x float> %rdx.shuf.1.0, %rdx.shuf.1.1
50
51 ; CHECK-LABEL: pairwise_hadd
52 ; CHECK: cost of 11 {{.*}} extractelement
53
54   %r = extractelement <4 x float> %bin.rdx.1, i32 0
55   %r2 = fadd float %r, %f1
56   ret float %r2
57 }
58 define fastcc float @pairwise_hadd_assoc(<4 x float> %rdx, float %f1) {
59   %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef,
60         <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef>
61   %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef,
62         <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
63   %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.1, %rdx.shuf.0.0
64   %rdx.shuf.1.0 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
65         <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>
66   %rdx.shuf.1.1 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
67         <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
68   %bin.rdx.1 = fadd <4 x float> %rdx.shuf.1.0, %rdx.shuf.1.1
69
70 ; CHECK-LABEL: pairwise_hadd_assoc
71 ; CHECK: cost of 11 {{.*}} extractelement
72
73   %r = extractelement <4 x float> %bin.rdx.1, i32 0
74   %r2 = fadd float %r, %f1
75   ret float %r2
76 }
77
78 define fastcc float @pairwise_hadd_skip_first(<4 x float> %rdx, float %f1) {
79   %rdx.shuf.0.0 = shufflevector <4 x float> %rdx, <4 x float> undef,
80         <4 x i32> <i32 0, i32 2 , i32 undef, i32 undef>
81   %rdx.shuf.0.1 = shufflevector <4 x float> %rdx, <4 x float> undef,
82         <4 x i32> <i32 1, i32 3, i32 undef, i32 undef>
83   %bin.rdx.0 = fadd <4 x float> %rdx.shuf.0.0, %rdx.shuf.0.1
84   %rdx.shuf.1.1 = shufflevector <4 x float> %bin.rdx.0, <4 x float> undef,
85         <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
86   %bin.rdx.1 = fadd <4 x float> %bin.rdx.0, %rdx.shuf.1.1
87
88 ; CHECK-LABEL: pairwise_hadd_skip_first
89 ; CHECK: cost of 11 {{.*}} extractelement
90
91   %r = extractelement <4 x float> %bin.rdx.1, i32 0
92   %r2 = fadd float %r, %f1
93   ret float %r2
94 }