1 ; RUN: llc -verify-machineinstrs -O3 -mcpu=pwr7 -enable-unsafe-fp-math < %s | FileCheck -allow-deprecated-dag-overlap %s -check-prefix=CHECK -check-prefix=CHECK-PWR
2 ; RUN: llc -verify-machineinstrs -O3 -mcpu=a2q -enable-unsafe-fp-math < %s | FileCheck -allow-deprecated-dag-overlap %s -check-prefix=CHECK -check-prefix=CHECK-QPX
3 target datalayout = "E-m:e-i64:64-n32:64"
4 target triple = "powerpc64-unknown-linux-gnu"
6 ; Verify that the first two adds are independent regardless of how the inputs are
7 ; commuted. The destination registers are used as source registers for the third add.
9 define float @reassociate_adds1(float %x0, float %x1, float %x2, float %x3) {
10 ; CHECK-LABEL: reassociate_adds1:
12 ; CHECK: fadds [[REG0:[0-9]+]], 1, 2
13 ; CHECK: fadds [[REG1:[0-9]+]], 3, 4
14 ; CHECK: fadds 1, [[REG0]], [[REG1]]
17 %t0 = fadd float %x0, %x1
18 %t1 = fadd float %t0, %x2
19 %t2 = fadd float %t1, %x3
23 define float @reassociate_adds2(float %x0, float %x1, float %x2, float %x3) {
24 ; CHECK-LABEL: reassociate_adds2:
26 ; CHECK: fadds [[REG0:[0-9]+]], 1, 2
27 ; CHECK: fadds [[REG1:[0-9]+]], 3, 4
28 ; CHECK: fadds 1, [[REG0]], [[REG1]]
31 %t0 = fadd float %x0, %x1
32 %t1 = fadd float %x2, %t0
33 %t2 = fadd float %t1, %x3
37 define float @reassociate_adds3(float %x0, float %x1, float %x2, float %x3) {
38 ; CHECK-LABEL: reassociate_adds3:
40 ; CHECK: fadds [[REG0:[0-9]+]], 1, 2
41 ; CHECK: fadds [[REG1:[0-9]+]], 3, 4
42 ; CHECK: fadds 1, [[REG0]], [[REG1]]
45 %t0 = fadd float %x0, %x1
46 %t1 = fadd float %t0, %x2
47 %t2 = fadd float %x3, %t1
51 define float @reassociate_adds4(float %x0, float %x1, float %x2, float %x3) {
52 ; CHECK-LABEL: reassociate_adds4:
54 ; CHECK: fadds [[REG0:[0-9]+]], 1, 2
55 ; CHECK: fadds [[REG1:[0-9]+]], 3, 4
56 ; CHECK: fadds 1, [[REG0]], [[REG1]]
59 %t0 = fadd float %x0, %x1
60 %t1 = fadd float %x2, %t0
61 %t2 = fadd float %x3, %t1
65 ; Verify that we reassociate some of these ops. The optimal balanced tree of adds is not
66 ; produced because that would cost more compile time.
68 define float @reassociate_adds5(float %x0, float %x1, float %x2, float %x3, float %x4, float %x5, float %x6, float %x7) {
69 ; CHECK-LABEL: reassociate_adds5:
71 ; CHECK-DAG: fadds [[REG12:[0-9]+]], 5, 6
72 ; CHECK-DAG: fadds [[REG0:[0-9]+]], 1, 2
73 ; CHECK-DAG: fadds [[REG11:[0-9]+]], 3, 4
74 ; CHECK: fadds [[REG13:[0-9]+]], [[REG12]], 7
75 ; CHECK-DAG: fadds [[REG1:[0-9]+]], [[REG0]], [[REG11]]
76 ; CHECK-DAG: fadds [[REG2:[0-9]+]], [[REG1]], [[REG13]]
77 ; CHECK: fadds 1, [[REG2]], 8
80 %t0 = fadd float %x0, %x1
81 %t1 = fadd float %t0, %x2
82 %t2 = fadd float %t1, %x3
83 %t3 = fadd float %t2, %x4
84 %t4 = fadd float %t3, %x5
85 %t5 = fadd float %t4, %x6
86 %t6 = fadd float %t5, %x7
90 ; Verify that we reassociate vector instructions too.
92 define <4 x float> @vector_reassociate_adds1(<4 x float> %x0, <4 x float> %x1, <4 x float> %x2, <4 x float> %x3) {
93 ; CHECK-LABEL: vector_reassociate_adds1:
95 ; CHECK-QPX: qvfadds [[REG0:[0-9]+]], 1, 2
96 ; CHECK-QPX: qvfadds [[REG1:[0-9]+]], 3, 4
97 ; CHECK-QPX: qvfadds 1, [[REG0]], [[REG1]]
98 ; CHECK-PWR: xvaddsp [[REG0:[0-9]+]], 34, 35
99 ; CHECK-PWR: xvaddsp [[REG1:[0-9]+]], 36, 37
100 ; CHECK-PWR: xvaddsp 34, [[REG0]], [[REG1]]
103 %t0 = fadd <4 x float> %x0, %x1
104 %t1 = fadd <4 x float> %t0, %x2
105 %t2 = fadd <4 x float> %t1, %x3
109 define <4 x float> @vector_reassociate_adds2(<4 x float> %x0, <4 x float> %x1, <4 x float> %x2, <4 x float> %x3) {
110 ; CHECK-LABEL: vector_reassociate_adds2:
112 ; CHECK-QPX: qvfadds [[REG0:[0-9]+]], 1, 2
113 ; CHECK-QPX: qvfadds [[REG1:[0-9]+]], 3, 4
114 ; CHECK-QPX: qvfadds 1, [[REG0]], [[REG1]]
115 ; CHECK-PWR: xvaddsp [[REG0:[0-9]+]], 34, 35
116 ; CHECK-PWR: xvaddsp [[REG1:[0-9]+]], 36, 37
117 ; CHECK-PWR: xvaddsp 34, [[REG0]], [[REG1]]
120 %t0 = fadd <4 x float> %x0, %x1
121 %t1 = fadd <4 x float> %x2, %t0
122 %t2 = fadd <4 x float> %t1, %x3
126 define <4 x float> @vector_reassociate_adds3(<4 x float> %x0, <4 x float> %x1, <4 x float> %x2, <4 x float> %x3) {
127 ; CHECK-LABEL: vector_reassociate_adds3:
129 ; CHECK-QPX: qvfadds [[REG0:[0-9]+]], 1, 2
130 ; CHECK-QPX: qvfadds [[REG1:[0-9]+]], 3, 4
131 ; CHECK-QPX: qvfadds 1, [[REG0]], [[REG1]]
132 ; CHECK-PWR: xvaddsp [[REG0:[0-9]+]], 34, 35
133 ; CHECK-PWR: xvaddsp [[REG1:[0-9]+]], 36, 37
134 ; CHECK-PWR: xvaddsp 34, [[REG0]], [[REG1]]
137 %t0 = fadd <4 x float> %x0, %x1
138 %t1 = fadd <4 x float> %t0, %x2
139 %t2 = fadd <4 x float> %x3, %t1
143 define <4 x float> @vector_reassociate_adds4(<4 x float> %x0, <4 x float> %x1, <4 x float> %x2, <4 x float> %x3) {
144 ; CHECK-LABEL: vector_reassociate_adds4:
146 ; CHECK-QPX: qvfadds [[REG0:[0-9]+]], 1, 2
147 ; CHECK-QPX: qvfadds [[REG1:[0-9]+]], 3, 4
148 ; CHECK-QPX: qvfadds 1, [[REG0]], [[REG1]]
149 ; CHECK-PWR: xvaddsp [[REG0:[0-9]+]], 34, 35
150 ; CHECK-PWR: xvaddsp [[REG1:[0-9]+]], 36, 37
151 ; CHECK-PWR: xvaddsp 34, [[REG0]], [[REG1]]
154 %t0 = fadd <4 x float> %x0, %x1
155 %t1 = fadd <4 x float> %x2, %t0
156 %t2 = fadd <4 x float> %x3, %t1
160 define float @reassociate_adds6(float %x0, float %x1, float %x2, float %x3) {
161 %t0 = fdiv float %x0, %x1
162 %t1 = fadd float %x2, %t0
163 %t2 = fadd float %x3, %t1
167 define float @reassociate_muls1(float %x0, float %x1, float %x2, float %x3) {
168 %t0 = fdiv float %x0, %x1
169 %t1 = fmul float %x2, %t0
170 %t2 = fmul float %x3, %t1
174 define double @reassociate_adds_double(double %x0, double %x1, double %x2, double %x3) {
175 %t0 = fdiv double %x0, %x1
176 %t1 = fadd double %x2, %t0
177 %t2 = fadd double %x3, %t1
181 define double @reassociate_muls_double(double %x0, double %x1, double %x2, double %x3) {
182 %t0 = fdiv double %x0, %x1
183 %t1 = fmul double %x2, %t0
184 %t2 = fmul double %x3, %t1