Sanjay Patel | 1eb5047 | 2014-09-11 16:08:44 +0000 | [diff] [blame] | 1 | ; RUN: llc -mtriple=x86_64-unknown-unknown -march=x86-64 < %s | FileCheck %s |
Matt Arsenault | 6cc0042 | 2014-08-16 10:14:19 +0000 | [diff] [blame] | 2 | |
| 3 | ; CHECK-LABEL: fmul2_f32: |
| 4 | ; CHECK: addss %xmm0, %xmm0 |
| 5 | define float @fmul2_f32(float %x) { |
| 6 | %y = fmul float %x, 2.0 |
| 7 | ret float %y |
| 8 | } |
| 9 | |
| 10 | ; fmul 2.0, x -> fadd x, x for vectors. |
| 11 | |
| 12 | ; CHECK-LABEL: fmul2_v4f32: |
| 13 | ; CHECK: addps %xmm0, %xmm0 |
| 14 | ; CHECK-NEXT: retq |
| 15 | define <4 x float> @fmul2_v4f32(<4 x float> %x) { |
| 16 | %y = fmul <4 x float> %x, <float 2.0, float 2.0, float 2.0, float 2.0> |
| 17 | ret <4 x float> %y |
| 18 | } |
| 19 | |
| 20 | ; CHECK-LABEL: constant_fold_fmul_v4f32: |
| 21 | ; CHECK: movaps |
| 22 | ; CHECK-NEXT: ret |
| 23 | define <4 x float> @constant_fold_fmul_v4f32(<4 x float> %x) { |
| 24 | %y = fmul <4 x float> <float 4.0, float 4.0, float 4.0, float 4.0>, <float 2.0, float 2.0, float 2.0, float 2.0> |
| 25 | ret <4 x float> %y |
| 26 | } |
| 27 | |
| 28 | ; CHECK-LABEL: fmul0_v4f32: |
| 29 | ; CHECK: xorps %xmm0, %xmm0 |
| 30 | ; CHECK-NEXT: retq |
| 31 | define <4 x float> @fmul0_v4f32(<4 x float> %x) #0 { |
| 32 | %y = fmul <4 x float> %x, <float 0.0, float 0.0, float 0.0, float 0.0> |
| 33 | ret <4 x float> %y |
| 34 | } |
| 35 | |
| 36 | ; CHECK-LABEL: fmul_c2_c4_v4f32: |
| 37 | ; CHECK-NOT: addps |
| 38 | ; CHECK: mulps |
| 39 | ; CHECK-NOT: mulps |
| 40 | ; CHECK-NEXT: ret |
| 41 | define <4 x float> @fmul_c2_c4_v4f32(<4 x float> %x) #0 { |
| 42 | %y = fmul <4 x float> %x, <float 2.0, float 2.0, float 2.0, float 2.0> |
| 43 | %z = fmul <4 x float> %y, <float 4.0, float 4.0, float 4.0, float 4.0> |
| 44 | ret <4 x float> %z |
| 45 | } |
| 46 | |
| 47 | ; CHECK-LABEL: fmul_c3_c4_v4f32: |
| 48 | ; CHECK-NOT: addps |
| 49 | ; CHECK: mulps |
| 50 | ; CHECK-NOT: mulps |
| 51 | ; CHECK-NEXT: ret |
| 52 | define <4 x float> @fmul_c3_c4_v4f32(<4 x float> %x) #0 { |
| 53 | %y = fmul <4 x float> %x, <float 3.0, float 3.0, float 3.0, float 3.0> |
| 54 | %z = fmul <4 x float> %y, <float 4.0, float 4.0, float 4.0, float 4.0> |
| 55 | ret <4 x float> %z |
| 56 | } |
| 57 | |
Sanjay Patel | 7bd228a | 2014-09-11 15:45:27 +0000 | [diff] [blame] | 58 | ; We should be able to pre-multiply the two constant vectors. |
Sanjay Patel | 1eb5047 | 2014-09-11 16:08:44 +0000 | [diff] [blame] | 59 | ; CHECK: float 5.000000e+00 |
| 60 | ; CHECK: float 1.200000e+01 |
| 61 | ; CHECK: float 2.100000e+01 |
| 62 | ; CHECK: float 3.200000e+01 |
Sanjay Patel | 7bd228a | 2014-09-11 15:45:27 +0000 | [diff] [blame] | 63 | ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat: |
| 64 | ; CHECK: mulps |
| 65 | ; CHECK-NOT: mulps |
| 66 | ; CHECK-NEXT: ret |
| 67 | define <4 x float> @fmul_v4f32_two_consts_no_splat(<4 x float> %x) #0 { |
| 68 | %y = fmul <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0> |
| 69 | %z = fmul <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0> |
| 70 | ret <4 x float> %z |
| 71 | } |
| 72 | |
| 73 | ; Same as above, but reverse operands to make sure non-canonical form is also handled. |
Sanjay Patel | 1eb5047 | 2014-09-11 16:08:44 +0000 | [diff] [blame] | 74 | ; CHECK: float 5.000000e+00 |
| 75 | ; CHECK: float 1.200000e+01 |
| 76 | ; CHECK: float 2.100000e+01 |
| 77 | ; CHECK: float 3.200000e+01 |
Sanjay Patel | 7bd228a | 2014-09-11 15:45:27 +0000 | [diff] [blame] | 78 | ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_non_canonical: |
| 79 | ; CHECK: mulps |
| 80 | ; CHECK-NOT: mulps |
| 81 | ; CHECK-NEXT: ret |
| 82 | define <4 x float> @fmul_v4f32_two_consts_no_splat_non_canonical(<4 x float> %x) #0 { |
| 83 | %y = fmul <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0>, %x |
| 84 | %z = fmul <4 x float> <float 5.0, float 6.0, float 7.0, float 8.0>, %y |
| 85 | ret <4 x float> %z |
| 86 | } |
| 87 | |
| 88 | ; More than one use of a constant multiply should not inhibit the optimization. |
| 89 | ; Instead of a chain of 2 dependent mults, this test will have 2 independent mults. |
Sanjay Patel | 1eb5047 | 2014-09-11 16:08:44 +0000 | [diff] [blame] | 90 | ; CHECK: float 5.000000e+00 |
| 91 | ; CHECK: float 1.200000e+01 |
| 92 | ; CHECK: float 2.100000e+01 |
| 93 | ; CHECK: float 3.200000e+01 |
Sanjay Patel | 7bd228a | 2014-09-11 15:45:27 +0000 | [diff] [blame] | 94 | ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_multiple_use: |
| 95 | ; CHECK: mulps |
| 96 | ; CHECK: mulps |
| 97 | ; CHECK: addps |
| 98 | ; CHECK: ret |
| 99 | define <4 x float> @fmul_v4f32_two_consts_no_splat_multiple_use(<4 x float> %x) #0 { |
| 100 | %y = fmul <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0> |
| 101 | %z = fmul <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0> |
| 102 | %a = fadd <4 x float> %y, %z |
| 103 | ret <4 x float> %a |
| 104 | } |
| 105 | |
Matt Arsenault | 6cc0042 | 2014-08-16 10:14:19 +0000 | [diff] [blame] | 106 | ; CHECK-LABEL: fmul_c2_c4_f32: |
| 107 | ; CHECK-NOT: addss |
| 108 | ; CHECK: mulss |
| 109 | ; CHECK-NOT: mulss |
| 110 | ; CHECK-NEXT: ret |
| 111 | define float @fmul_c2_c4_f32(float %x) #0 { |
| 112 | %y = fmul float %x, 2.0 |
| 113 | %z = fmul float %y, 4.0 |
| 114 | ret float %z |
| 115 | } |
| 116 | |
| 117 | ; CHECK-LABEL: fmul_c3_c4_f32: |
| 118 | ; CHECK-NOT: addss |
| 119 | ; CHECK: mulss |
| 120 | ; CHECK-NOT: mulss |
| 121 | ; CHECK-NET: ret |
| 122 | define float @fmul_c3_c4_f32(float %x) #0 { |
| 123 | %y = fmul float %x, 3.0 |
| 124 | %z = fmul float %y, 4.0 |
| 125 | ret float %z |
| 126 | } |
| 127 | |
| 128 | ; CHECK-LABEL: fmul_fneg_fneg_f32: |
| 129 | ; CHECK: mulss %xmm1, %xmm0 |
| 130 | ; CHECK-NEXT: retq |
| 131 | define float @fmul_fneg_fneg_f32(float %x, float %y) { |
| 132 | %x.neg = fsub float -0.0, %x |
| 133 | %y.neg = fsub float -0.0, %y |
| 134 | %mul = fmul float %x.neg, %y.neg |
| 135 | ret float %mul |
| 136 | } |
| 137 | ; CHECK-LABEL: fmul_fneg_fneg_v4f32: |
NAKAMURA Takumi | 067d4c7 | 2014-08-16 22:28:37 +0000 | [diff] [blame] | 138 | ; CHECK: mulps {{%xmm1|\(%rdx\)}}, %xmm0 |
Matt Arsenault | 6cc0042 | 2014-08-16 10:14:19 +0000 | [diff] [blame] | 139 | ; CHECK-NEXT: retq |
| 140 | define <4 x float> @fmul_fneg_fneg_v4f32(<4 x float> %x, <4 x float> %y) { |
| 141 | %x.neg = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %x |
| 142 | %y.neg = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %y |
| 143 | %mul = fmul <4 x float> %x.neg, %y.neg |
| 144 | ret <4 x float> %mul |
| 145 | } |
| 146 | |
| 147 | attributes #0 = { "less-precise-fpmad"="true" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "unsafe-fp-math"="true" } |