1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=x86_64-unknown-unknown < %s | FileCheck %s
define <4 x float> @fmul_zero_not_fast(<4 x float> %x) nounwind {
; CHECK-LABEL: fmul_zero_not_fast:
; CHECK: # %bb.0:
; CHECK-NEXT: xorps %xmm1, %xmm1
; CHECK-NEXT: mulps %xmm1, %xmm0
; CHECK-NEXT: retq
%r = fmul <4 x float> %x, zeroinitializer
ret <4 x float> %r
}
define <4 x float> @fmul_zero_nsz_nnan(<4 x float> %x) nounwind {
; CHECK-LABEL: fmul_zero_nsz_nnan:
; CHECK: # %bb.0:
; CHECK-NEXT: xorps %xmm0, %xmm0
; CHECK-NEXT: retq
%r = fmul nsz nnan <4 x float> %x, zeroinitializer
ret <4 x float> %r
}
define <4 x float> @fmul_zero_nsz_nnan_undef(<4 x float> %x) nounwind {
; CHECK-LABEL: fmul_zero_nsz_nnan_undef:
; CHECK: # %bb.0:
; CHECK-NEXT: xorps %xmm0, %xmm0
; CHECK-NEXT: retq
%r = fmul nsz nnan <4 x float> %x, <float 0.0, float 0.0, float 0.0, float undef>
ret <4 x float> %r
}
define float @fmul2_f32(float %x) {
; CHECK-LABEL: fmul2_f32:
; CHECK: # %bb.0:
; CHECK-NEXT: addss %xmm0, %xmm0
; CHECK-NEXT: retq
%y = fmul float %x, 2.0
ret float %y
}
; fmul 2.0, x -> fadd x, x for vectors.
define <4 x float> @fmul2_v4f32(<4 x float> %x) {
; CHECK-LABEL: fmul2_v4f32:
; CHECK: # %bb.0:
; CHECK-NEXT: addps %xmm0, %xmm0
; CHECK-NEXT: retq
%y = fmul <4 x float> %x, <float 2.0, float 2.0, float 2.0, float 2.0>
ret <4 x float> %y
}
define <4 x float> @fmul2_v4f32_undef(<4 x float> %x) {
; CHECK-LABEL: fmul2_v4f32_undef:
; CHECK: # %bb.0:
; CHECK-NEXT: addps %xmm0, %xmm0
; CHECK-NEXT: retq
%y = fmul <4 x float> %x, <float undef, float 2.0, float 2.0, float 2.0>
ret <4 x float> %y
}
define <4 x float> @constant_fold_fmul_v4f32(<4 x float> %x) {
; CHECK-LABEL: constant_fold_fmul_v4f32:
; CHECK: # %bb.0:
; CHECK-NEXT: movaps {{.*#+}} xmm0 = [8.0E+0,8.0E+0,8.0E+0,8.0E+0]
; CHECK-NEXT: retq
%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>
ret <4 x float> %y
}
define <4 x float> @constant_fold_fmul_v4f32_undef(<4 x float> %x) {
; CHECK-LABEL: constant_fold_fmul_v4f32_undef:
; CHECK: # %bb.0:
; CHECK-NEXT: movaps {{.*#+}} xmm0 = [8.0E+0,NaN,8.0E+0,NaN]
; CHECK-NEXT: retq
%y = fmul <4 x float> <float 4.0, float undef, float 4.0, float 4.0>, <float 2.0, float 2.0, float 2.0, float undef>
ret <4 x float> %y
}
define <4 x float> @fmul0_v4f32_nsz_nnan(<4 x float> %x) {
; CHECK-LABEL: fmul0_v4f32_nsz_nnan:
; CHECK: # %bb.0:
; CHECK-NEXT: xorps %xmm0, %xmm0
; CHECK-NEXT: retq
%y = fmul nnan nsz <4 x float> %x, <float 0.0, float 0.0, float 0.0, float 0.0>
ret <4 x float> %y
}
define <4 x float> @fmul0_v4f32_undef(<4 x float> %x) {
; CHECK-LABEL: fmul0_v4f32_undef:
; CHECK: # %bb.0:
; CHECK-NEXT: xorps %xmm0, %xmm0
; CHECK-NEXT: retq
%y = fmul nnan nsz <4 x float> %x, <float undef, float 0.0, float undef, float 0.0>
ret <4 x float> %y
}
define <4 x float> @fmul_c2_c4_v4f32(<4 x float> %x) {
; CHECK-LABEL: fmul_c2_c4_v4f32:
; CHECK: # %bb.0:
; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; CHECK-NEXT: retq
%y = fmul fast <4 x float> %x, <float 2.0, float 2.0, float 2.0, float 2.0>
%z = fmul fast <4 x float> %y, <float 4.0, float 4.0, float 4.0, float 4.0>
ret <4 x float> %z
}
define <4 x float> @fmul_c3_c4_v4f32(<4 x float> %x) {
; CHECK-LABEL: fmul_c3_c4_v4f32:
; CHECK: # %bb.0:
; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; CHECK-NEXT: retq
%y = fmul fast <4 x float> %x, <float 3.0, float 3.0, float 3.0, float 3.0>
%z = fmul fast <4 x float> %y, <float 4.0, float 4.0, float 4.0, float 4.0>
ret <4 x float> %z
}
; CHECK: float 5
; CHECK: float 12
; CHECK: float 21
; CHECK: float 32
; We should be able to pre-multiply the two constant vectors.
define <4 x float> @fmul_v4f32_two_consts_no_splat(<4 x float> %x) {
; CHECK-LABEL: fmul_v4f32_two_consts_no_splat:
; CHECK: # %bb.0:
; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; CHECK-NEXT: retq
%y = fmul fast <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>
%z = fmul fast <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>
ret <4 x float> %z
}
; Same as above, but reverse operands to make sure non-canonical form is also handled.
define <4 x float> @fmul_v4f32_two_consts_no_splat_non_canonical(<4 x float> %x) {
; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_non_canonical:
; CHECK: # %bb.0:
; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; CHECK-NEXT: retq
%y = fmul fast <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0>, %x
%z = fmul fast <4 x float> <float 5.0, float 6.0, float 7.0, float 8.0>, %y
ret <4 x float> %z
}
; Node-level FMF and no function-level attributes.
define <4 x float> @fmul_v4f32_two_consts_no_splat_reassoc(<4 x float> %x) {
; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_reassoc:
; CHECK: # %bb.0:
; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; CHECK-NEXT: retq
%y = fmul <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>
%z = fmul reassoc <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>
ret <4 x float> %z
}
; Multiplication by 2.0 is a special case because that gets converted to fadd x, x.
define <4 x float> @fmul_v4f32_two_consts_no_splat_reassoc_2(<4 x float> %x) {
; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_reassoc_2:
; CHECK: # %bb.0:
; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; CHECK-NEXT: retq
%y = fadd <4 x float> %x, %x
%z = fmul reassoc <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>
ret <4 x float> %z
}
; CHECK: float 6
; CHECK: float 14
; CHECK: float 24
; CHECK: float 36
; More than one use of a constant multiply should not inhibit the optimization.
; Instead of a chain of 2 dependent mults, this test will have 2 independent mults.
define <4 x float> @fmul_v4f32_two_consts_no_splat_multiple_use(<4 x float> %x) {
; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_multiple_use:
; CHECK: # %bb.0:
; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; CHECK-NEXT: retq
%y = fmul fast <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>
%z = fmul fast <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>
%a = fadd fast <4 x float> %y, %z
ret <4 x float> %a
}
; PR22698 - http://llvm.org/bugs/show_bug.cgi?id=22698
; Make sure that we don't infinite loop swapping constants back and forth.
; CHECK: float 24
; CHECK: float 24
; CHECK: float 24
; CHECK: float 24
define <4 x float> @PR22698_splats(<4 x float> %a) {
; CHECK-LABEL: PR22698_splats:
; CHECK: # %bb.0:
; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; CHECK-NEXT: retq
%mul1 = fmul fast <4 x float> <float 2.0, float 2.0, float 2.0, float 2.0>, <float 3.0, float 3.0, float 3.0, float 3.0>
%mul2 = fmul fast <4 x float> <float 4.0, float 4.0, float 4.0, float 4.0>, %mul1
%mul3 = fmul fast <4 x float> %a, %mul2
ret <4 x float> %mul3
}
; Same as above, but verify that non-splat vectors are handled correctly too.
; CHECK: float 45
; CHECK: float 120
; CHECK: float 231
; CHECK: float 384
define <4 x float> @PR22698_no_splats(<4 x float> %a) {
; CHECK-LABEL: PR22698_no_splats:
; CHECK: # %bb.0:
; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; CHECK-NEXT: retq
%mul1 = fmul fast <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0>, <float 5.0, float 6.0, float 7.0, float 8.0>
%mul2 = fmul fast <4 x float> <float 9.0, float 10.0, float 11.0, float 12.0>, %mul1
%mul3 = fmul fast <4 x float> %a, %mul2
ret <4 x float> %mul3
}
define float @fmul_c2_c4_f32(float %x) {
; CHECK-LABEL: fmul_c2_c4_f32:
; CHECK: # %bb.0:
; CHECK-NEXT: mulss {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; CHECK-NEXT: retq
%y = fmul fast float %x, 2.0
%z = fmul fast float %y, 4.0
ret float %z
}
define float @fmul_c3_c4_f32(float %x) {
; CHECK-LABEL: fmul_c3_c4_f32:
; CHECK: # %bb.0:
; CHECK-NEXT: mulss {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
; CHECK-NEXT: retq
%y = fmul fast float %x, 3.0
%z = fmul fast float %y, 4.0
ret float %z
}
define float @fmul_fneg_fneg_f32(float %x, float %y) {
; CHECK-LABEL: fmul_fneg_fneg_f32:
; CHECK: # %bb.0:
; CHECK-NEXT: mulss %xmm1, %xmm0
; CHECK-NEXT: retq
%x.neg = fsub float -0.0, %x
%y.neg = fsub float -0.0, %y
%mul = fmul float %x.neg, %y.neg
ret float %mul
}
define <4 x float> @fmul_fneg_fneg_v4f32(<4 x float> %x, <4 x float> %y) {
; CHECK-LABEL: fmul_fneg_fneg_v4f32:
; CHECK: # %bb.0:
; CHECK-NEXT: mulps %xmm1, %xmm0
; CHECK-NEXT: retq
%x.neg = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %x
%y.neg = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %y
%mul = fmul <4 x float> %x.neg, %y.neg
ret <4 x float> %mul
}
; PR47517 - this could crash if we create 'fmul x, 0.0' nodes
; that do not constant fold in a particular order.
define float @getNegatedExpression_crash(float* %p) {
; CHECK-LABEL: getNegatedExpression_crash:
; CHECK: # %bb.0:
; CHECK-NEXT: movl $0, (%rdi)
; CHECK-NEXT: xorps %xmm0, %xmm0
; CHECK-NEXT: retq
store float 0.0, float* %p, align 1
%real = load float, float* %p, align 1
%r2 = fmul fast float %real, %real
%t1 = fmul fast float %real, 42.0
%t2 = fmul fast float %real, %t1
%mul_ac56 = fmul fast float %t2, %t1
%mul_ac72 = fmul fast float %r2, %mul_ac56
ret float %mul_ac72
}
|