1 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mcpu=x86-64 | FileCheck %s
3 ; More than one 'arcp' division using a single divisor operand
4 ; should be converted into a reciprocal and multiplication.
6 ; Don't do anything for just one division.
8 define float @div1_arcp(float %x, float %y, float %z) {
9 ; CHECK-LABEL: div1_arcp:
11 ; CHECK-NEXT: divss %xmm1, %xmm0
13 %div1 = fdiv arcp float %x, %y
17 ; All math instructions are 'arcp', so optimize.
19 define float @div2_arcp_all(float %x, float %y, float %z) {
20 ; CHECK-LABEL: div2_arcp_all:
22 ; CHECK-NEXT: movss {{.*#+}} xmm3 = mem[0],zero,zero,zero
23 ; CHECK-NEXT: divss %xmm2, %xmm3
24 ; CHECK-NEXT: mulss %xmm3, %xmm0
25 ; CHECK-NEXT: mulss %xmm1, %xmm0
26 ; CHECK-NEXT: mulss %xmm3, %xmm0
28 %div1 = fdiv arcp float %x, %z
29 %mul = fmul arcp float %div1, %y
30 %div2 = fdiv arcp float %mul, %z
34 ; The first division is not 'arcp', so do not optimize.
36 define float @div2_arcp_partial1(float %x, float %y, float %z) {
37 ; CHECK-LABEL: div2_arcp_partial1:
39 ; CHECK-NEXT: divss %xmm2, %xmm0
40 ; CHECK-NEXT: mulss %xmm1, %xmm0
41 ; CHECK-NEXT: divss %xmm2, %xmm0
43 %div1 = fdiv float %x, %z
44 %mul = fmul arcp float %div1, %y
45 %div2 = fdiv arcp float %mul, %z
49 ; The second division is not 'arcp', so do not optimize.
51 define float @div2_arcp_partial2(float %x, float %y, float %z) {
52 ; CHECK-LABEL: div2_arcp_partial2:
54 ; CHECK-NEXT: divss %xmm2, %xmm0
55 ; CHECK-NEXT: mulss %xmm1, %xmm0
56 ; CHECK-NEXT: divss %xmm2, %xmm0
58 %div1 = fdiv arcp float %x, %z
59 %mul = fmul arcp float %div1, %y
60 %div2 = fdiv float %mul, %z
64 ; The multiply is not 'arcp', but that does not prevent optimizing the divisions.
66 define float @div2_arcp_partial3(float %x, float %y, float %z) {
67 ; CHECK-LABEL: div2_arcp_partial3:
69 ; CHECK-NEXT: movss {{.*#+}} xmm3 = mem[0],zero,zero,zero
70 ; CHECK-NEXT: divss %xmm2, %xmm3
71 ; CHECK-NEXT: mulss %xmm3, %xmm0
72 ; CHECK-NEXT: mulss %xmm1, %xmm0
73 ; CHECK-NEXT: mulss %xmm3, %xmm0
75 %div1 = fdiv arcp float %x, %z
76 %mul = fmul float %div1, %y
77 %div2 = fdiv arcp float %mul, %z
81 ; If the reciprocal is already calculated, we should not
82 ; generate an extra multiplication by 1.0.
84 define double @div3_arcp(double %x, double %y, double %z) {
85 ; CHECK-LABEL: div3_arcp:
87 ; CHECK-NEXT: movsd{{.*#+}} xmm2 = mem[0],zero
88 ; CHECK-NEXT: divsd %xmm1, %xmm2
89 ; CHECK-NEXT: mulsd %xmm2, %xmm0
90 ; CHECK-NEXT: addsd %xmm2, %xmm0
92 %div1 = fdiv fast double 1.0, %y
93 %div2 = fdiv fast double %x, %y
94 %ret = fadd fast double %div2, %div1
98 define void @PR24141() {
99 ; CHECK-LABEL: PR24141:
107 %x.0 = phi double [ undef, %entry ], [ %div, %while.body ]
108 %call = call { double, double } @g(double %x.0)
109 %xv0 = extractvalue { double, double } %call, 0
110 %xv1 = extractvalue { double, double } %call, 1
111 %div = fdiv arcp double %xv0, %xv1
115 declare { double, double } @g(double)