1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -enable-unsafe-fp-math | FileCheck %s
4 define double @exact(double %x) {
5 ; Exact division by a constant converted to multiplication.
8 ; CHECK-NEXT: mulsd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
10 %div = fdiv double %x, 2.0
14 define double @inexact(double %x) {
15 ; Inexact division by a constant converted to multiplication.
16 ; CHECK-LABEL: inexact:
18 ; CHECK-NEXT: mulsd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
20 %div = fdiv double %x, 0x41DFFFFFFFC00000
24 define double @funky(double %x) {
25 ; No conversion to multiplication if too funky.
28 ; CHECK-NEXT: xorpd %xmm1, %xmm1
29 ; CHECK-NEXT: divsd %xmm1, %xmm0
31 %div = fdiv double %x, 0.0
35 define double @denormal1(double %x) {
36 ; Don't generate multiplication by a denormal.
37 ; CHECK-LABEL: denormal1:
39 ; CHECK-NEXT: divsd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
41 %div = fdiv double %x, 0x7FD0000000000001
45 define double @denormal2(double %x) {
46 ; Don't generate multiplication by a denormal.
47 ; CHECK-LABEL: denormal2:
49 ; CHECK-NEXT: divsd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
51 %div = fdiv double %x, 0x7FEFFFFFFFFFFFFF
55 ; Deleting the negates does not require unsafe-fp-math.
57 define float @double_negative(float %x, float %y) #0 {
58 ; CHECK-LABEL: double_negative:
60 ; CHECK-NEXT: divss %xmm1, %xmm0
62 %neg1 = fsub float -0.0, %x
63 %neg2 = fsub float -0.0, %y
64 %div = fdiv float %neg1, %neg2
68 define <4 x float> @double_negative_vector(<4 x float> %x, <4 x float> %y) #0 {
69 ; CHECK-LABEL: double_negative_vector:
71 ; CHECK-NEXT: divps %xmm1, %xmm0
73 %neg1 = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %x
74 %neg2 = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %y
75 %div = fdiv <4 x float> %neg1, %neg2
79 ; This test used to fail, depending on how llc was built (e.g. using
80 ; clang/gcc), due to order of argument evaluation not being well defined. We
81 ; ended up hitting llvm_unreachable in getNegatedExpression when building with
82 ; gcc. Just make sure that we get a deterministic result.
83 define float @fdiv_fneg_combine(float %a0, float %a1, float %a2) #0 {
84 ; CHECK-LABEL: fdiv_fneg_combine:
86 ; CHECK-NEXT: movaps %xmm0, %xmm3
87 ; CHECK-NEXT: subss %xmm1, %xmm3
88 ; CHECK-NEXT: subss %xmm0, %xmm1
89 ; CHECK-NEXT: mulss %xmm2, %xmm1
90 ; CHECK-NEXT: subss %xmm2, %xmm3
91 ; CHECK-NEXT: divss %xmm3, %xmm1
92 ; CHECK-NEXT: movaps %xmm1, %xmm0
94 %sub1 = fsub fast float %a0, %a1
95 %mul2 = fmul fast float %sub1, %a2
96 %neg = fneg fast float %a0
97 %add3 = fadd fast float %a1, %neg
98 %sub4 = fadd fast float %add3, %a2
99 %div5 = fdiv fast float %mul2, %sub4
103 attributes #0 = { "unsafe-fp-math"="false" }