1 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mcpu=x86-64 | FileCheck %s
3 ; Anything more than one division using a single divisor operand
4 ; should be converted into a reciprocal and multiplication.
6 define float @div1_arcp(float %x, float %y, float %z) #0 {
7 ; CHECK-LABEL: div1_arcp:
9 ; CHECK-NEXT: divss %xmm1, %xmm0
11 %div1 = fdiv arcp float %x, %y
15 define float @div2_arcp(float %x, float %y, float %z) #0 {
16 ; CHECK-LABEL: div2_arcp:
18 ; CHECK-NEXT: movss {{.*#+}} xmm3 = mem[0],zero,zero,zero
19 ; CHECK-NEXT: divss %xmm2, %xmm3
20 ; CHECK-NEXT: mulss %xmm1, %xmm0
21 ; CHECK-NEXT: mulss %xmm3, %xmm0
22 ; CHECK-NEXT: mulss %xmm3, %xmm0
24 %div1 = fdiv arcp float %x, %z
25 %mul = fmul arcp float %div1, %y
26 %div2 = fdiv arcp float %mul, %z
30 ; If the reciprocal is already calculated, we should not
31 ; generate an extra multiplication by 1.0.
33 define double @div3_arcp(double %x, double %y, double %z) #0 {
34 ; CHECK-LABEL: div3_arcp:
36 ; CHECK-NEXT: movsd{{.*#+}} xmm2 = mem[0],zero
37 ; CHECK-NEXT: divsd %xmm1, %xmm2
38 ; CHECK-NEXT: mulsd %xmm2, %xmm0
39 ; CHECK-NEXT: addsd %xmm2, %xmm0
41 %div1 = fdiv fast double 1.0, %y
42 %div2 = fdiv fast double %x, %y
43 %ret = fadd fast double %div2, %div1
47 define void @PR24141() #0 {
48 ; CHECK-LABEL: PR24141:
56 %x.0 = phi double [ undef, %entry ], [ %div, %while.body ]
57 %call = call { double, double } @g(double %x.0)
58 %xv0 = extractvalue { double, double } %call, 0
59 %xv1 = extractvalue { double, double } %call, 1
60 %div = fdiv double %xv0, %xv1
64 declare { double, double } @g(double)
66 ; FIXME: If the backend understands 'arcp', then this attribute is unnecessary.
67 attributes #0 = { "unsafe-fp-math"="true" }