1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64le-linux-gnu | FileCheck %s
4 ; Verify that the fold of a*b-c*d respect the uses of a*b
5 define double @fsub1(double %a, double %b, double %c, double %d) {
7 ; CHECK: # %bb.0: # %entry
8 ; CHECK-NEXT: xsmuldp 0, 2, 1
10 ; CHECK-NEXT: xsnmsubadp 1, 4, 3
11 ; CHECK-NEXT: xsmuldp 1, 0, 1
14 %mul = fmul contract reassoc double %b, %a
15 %mul1 = fmul contract reassoc double %d, %c
16 %sub = fsub contract reassoc nsz double %mul, %mul1
17 %mul3 = fmul contract reassoc double %mul, %sub
21 ; Verify that the fold of a*b-c*d respect the uses of c*d
22 define double @fsub2(double %a, double %b, double %c, double %d) {
24 ; CHECK: # %bb.0: # %entry
25 ; CHECK-NEXT: xsmuldp 0, 4, 3
26 ; CHECK-NEXT: fmr 3, 0
27 ; CHECK-NEXT: xsmsubadp 3, 2, 1
28 ; CHECK-NEXT: xsmuldp 1, 0, 3
31 %mul = fmul contract reassoc double %b, %a
32 %mul1 = fmul contract reassoc double %d, %c
33 %sub = fsub contract reassoc double %mul, %mul1
34 %mul3 = fmul contract reassoc double %mul1, %sub
38 ; Verify that the fold of a*b-c*d if there is no uses of a*b and c*d
39 define double @fsub3(double %a, double %b, double %c, double %d) {
41 ; CHECK: # %bb.0: # %entry
42 ; CHECK-NEXT: xsmuldp 0, 4, 3
43 ; CHECK-NEXT: xsmsubadp 0, 2, 1
44 ; CHECK-NEXT: fmr 1, 0
47 %mul = fmul contract reassoc double %b, %a
48 %mul1 = fmul contract reassoc double %d, %c
49 %sub = fsub contract reassoc double %mul, %mul1
53 ; Verify that the fold of a*b+c*d respect the uses of a*b
54 define double @fadd1(double %a, double %b, double %c, double %d) {
56 ; CHECK: # %bb.0: # %entry
57 ; CHECK-NEXT: xsmuldp 0, 2, 1
58 ; CHECK-NEXT: fmr 1, 0
59 ; CHECK-NEXT: xsmaddadp 1, 4, 3
60 ; CHECK-NEXT: xsmuldp 1, 0, 1
63 %mul = fmul contract reassoc double %b, %a
64 %mul1 = fmul contract reassoc double %d, %c
65 %add = fadd contract reassoc double %mul1, %mul
66 %mul3 = fmul contract reassoc double %mul, %add
70 ; Verify that the fold of a*b+c*d respect the uses of c*d
71 define double @fadd2(double %a, double %b, double %c, double %d) {
73 ; CHECK: # %bb.0: # %entry
74 ; CHECK-NEXT: xsmuldp 0, 4, 3
75 ; CHECK-NEXT: fmr 3, 0
76 ; CHECK-NEXT: xsmaddadp 3, 2, 1
77 ; CHECK-NEXT: xsmuldp 1, 0, 3
80 %mul = fmul contract reassoc double %b, %a
81 %mul1 = fmul contract reassoc double %d, %c
82 %add = fadd contract reassoc double %mul1, %mul
83 %mul3 = fmul contract reassoc double %mul1, %add
87 ; Verify that the fold of a*b+c*d if there is no uses of a*b and c*d
88 define double @fadd3(double %a, double %b, double %c, double %d) {
90 ; CHECK: # %bb.0: # %entry
91 ; CHECK-NEXT: xsmuldp 1, 2, 1
92 ; CHECK-NEXT: xsmaddadp 1, 4, 3
95 %mul = fmul contract reassoc double %b, %a
96 %mul1 = fmul contract reassoc double %d, %c
97 %add = fadd contract reassoc double %mul1, %mul
101 define double @fma_multi_uses1(double %a, double %b, double %c, double %d, ptr %p1, ptr %p2, ptr %p3) {
102 ; CHECK-LABEL: fma_multi_uses1:
104 ; CHECK-NEXT: xsmuldp 1, 1, 2
105 ; CHECK-NEXT: xsmuldp 0, 3, 4
106 ; CHECK-NEXT: stfd 1, 0(7)
107 ; CHECK-NEXT: stfd 1, 0(8)
108 ; CHECK-NEXT: xsnmsubadp 1, 3, 4
109 ; CHECK-NEXT: stfd 0, 0(9)
111 %ab = fmul contract reassoc double %a, %b
112 %cd = fmul contract reassoc double %c, %d
113 store double %ab, ptr %p1 ; extra use of %ab
114 store double %ab, ptr %p2 ; another extra use of %ab
115 store double %cd, ptr %p3 ; extra use of %cd
116 %r = fsub contract reassoc nsz double %ab, %cd
120 define double @fma_multi_uses2(double %a, double %b, double %c, double %d, ptr %p1, ptr %p2, ptr %p3) {
121 ; CHECK-LABEL: fma_multi_uses2:
123 ; CHECK-NEXT: xsmuldp 5, 1, 2
124 ; CHECK-NEXT: xsmuldp 0, 3, 4
125 ; CHECK-NEXT: stfd 5, 0(7)
126 ; CHECK-NEXT: stfd 0, 0(8)
127 ; CHECK-NEXT: stfd 0, 0(9)
128 ; CHECK-NEXT: xsmsubadp 0, 1, 2
129 ; CHECK-NEXT: fmr 1, 0
131 %ab = fmul contract reassoc double %a, %b
132 %cd = fmul contract reassoc double %c, %d
133 store double %ab, ptr %p1 ; extra use of %ab
134 store double %cd, ptr %p2 ; extra use of %cd
135 store double %cd, ptr %p3 ; another extra use of %cd
136 %r = fsub contract reassoc double %ab, %cd
140 define double @fma_multi_uses3(double %a, double %b, double %c, double %d, double %f, double %g, ptr %p1, ptr %p2, ptr %p3) {
141 ; CHECK-LABEL: fma_multi_uses3:
143 ; CHECK-NEXT: xsmuldp 0, 1, 2
144 ; CHECK-NEXT: xsmuldp 1, 5, 6
145 ; CHECK-NEXT: ld 3, 96(1)
146 ; CHECK-NEXT: stfd 0, 0(9)
147 ; CHECK-NEXT: stfd 0, 0(10)
148 ; CHECK-NEXT: stfd 1, 0(3)
149 ; CHECK-NEXT: xsnmsubadp 1, 3, 4
150 ; CHECK-NEXT: xsnmsubadp 0, 3, 4
151 ; CHECK-NEXT: xsadddp 1, 0, 1
153 %ab = fmul contract reassoc double %a, %b
154 %cd = fmul contract reassoc double %c, %d
155 %fg = fmul contract reassoc double %f, %g
156 store double %ab, ptr %p1 ; extra use of %ab
157 store double %ab, ptr %p2 ; another extra use of %ab
158 store double %fg, ptr %p3 ; extra use of %fg
159 %q = fsub contract reassoc nsz double %fg, %cd ; The uses of %cd reduce to 1 after %r is folded. 2 uses of %fg, fold %cd, remove def of %cd
160 %r = fsub contract reassoc nsz double %ab, %cd ; Fold %r before %q. 3 uses of %ab, 2 uses of %cd, fold %cd
161 %add = fadd contract reassoc double %r, %q