283 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc -mtriple=x86_64-unknown-unknown < %s | FileCheck %s3 4define <4 x float> @fmul_zero_not_fast(<4 x float> %x) nounwind {5; CHECK-LABEL: fmul_zero_not_fast:6; CHECK: # %bb.0:7; CHECK-NEXT: xorps %xmm1, %xmm18; CHECK-NEXT: mulps %xmm1, %xmm09; CHECK-NEXT: retq10 %r = fmul <4 x float> %x, zeroinitializer11 ret <4 x float> %r12}13 14define <4 x float> @fmul_zero_nsz_nnan(<4 x float> %x) nounwind {15; CHECK-LABEL: fmul_zero_nsz_nnan:16; CHECK: # %bb.0:17; CHECK-NEXT: xorps %xmm0, %xmm018; CHECK-NEXT: retq19 %r = fmul nsz nnan <4 x float> %x, zeroinitializer20 ret <4 x float> %r21}22 23define <4 x float> @fmul_zero_nsz_nnan_undef(<4 x float> %x) nounwind {24; CHECK-LABEL: fmul_zero_nsz_nnan_undef:25; CHECK: # %bb.0:26; CHECK-NEXT: xorps %xmm0, %xmm027; CHECK-NEXT: retq28 %r = fmul nsz nnan <4 x float> %x, <float 0.0, float 0.0, float 0.0, float undef>29 ret <4 x float> %r30}31 32define float @fmul2_f32(float %x) {33; CHECK-LABEL: fmul2_f32:34; CHECK: # %bb.0:35; CHECK-NEXT: addss %xmm0, %xmm036; CHECK-NEXT: retq37 %y = fmul float %x, 2.038 ret float %y39}40 41; fmul 2.0, x -> fadd x, x for vectors.42 43define <4 x float> @fmul2_v4f32(<4 x float> %x) {44; CHECK-LABEL: fmul2_v4f32:45; CHECK: # %bb.0:46; CHECK-NEXT: addps %xmm0, %xmm047; CHECK-NEXT: retq48 %y = fmul <4 x float> %x, <float 2.0, float 2.0, float 2.0, float 2.0>49 ret <4 x float> %y50}51 52define <4 x float> @fmul2_v4f32_undef(<4 x float> %x) {53; CHECK-LABEL: fmul2_v4f32_undef:54; CHECK: # %bb.0:55; CHECK-NEXT: addps %xmm0, %xmm056; CHECK-NEXT: retq57 %y = fmul <4 x float> %x, <float undef, float 2.0, float 2.0, float 2.0>58 ret <4 x float> %y59}60 61define <4 x float> @constant_fold_fmul_v4f32(<4 x float> %x) {62; CHECK-LABEL: constant_fold_fmul_v4f32:63; CHECK: # %bb.0:64; CHECK-NEXT: movaps {{.*#+}} xmm0 = [8.0E+0,8.0E+0,8.0E+0,8.0E+0]65; CHECK-NEXT: retq66 %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>67 ret <4 x float> %y68}69 70define <4 x float> @constant_fold_fmul_v4f32_undef(<4 x float> %x) {71; CHECK-LABEL: constant_fold_fmul_v4f32_undef:72; CHECK: # %bb.0:73; CHECK-NEXT: movaps {{.*#+}} xmm0 = [8.0E+0,NaN,8.0E+0,NaN]74; CHECK-NEXT: retq75 %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>76 ret <4 x float> %y77}78 79define <4 x float> @fmul0_v4f32_nsz_nnan(<4 x float> %x) {80; CHECK-LABEL: fmul0_v4f32_nsz_nnan:81; CHECK: # %bb.0:82; CHECK-NEXT: xorps %xmm0, %xmm083; CHECK-NEXT: retq84 %y = fmul nnan nsz <4 x float> %x, <float 0.0, float 0.0, float 0.0, float 0.0>85 ret <4 x float> %y86}87 88define <4 x float> @fmul0_v4f32_undef(<4 x float> %x) {89; CHECK-LABEL: fmul0_v4f32_undef:90; CHECK: # %bb.0:91; CHECK-NEXT: xorps %xmm0, %xmm092; CHECK-NEXT: retq93 %y = fmul nnan nsz <4 x float> %x, <float undef, float 0.0, float undef, float 0.0>94 ret <4 x float> %y95}96 97define <4 x float> @fmul_c2_c4_v4f32(<4 x float> %x) {98; CHECK-LABEL: fmul_c2_c4_v4f32:99; CHECK: # %bb.0:100; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0101; CHECK-NEXT: retq102 %y = fmul fast <4 x float> %x, <float 2.0, float 2.0, float 2.0, float 2.0>103 %z = fmul fast <4 x float> %y, <float 4.0, float 4.0, float 4.0, float 4.0>104 ret <4 x float> %z105}106 107define <4 x float> @fmul_c3_c4_v4f32(<4 x float> %x) {108; CHECK-LABEL: fmul_c3_c4_v4f32:109; CHECK: # %bb.0:110; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0111; CHECK-NEXT: retq112 %y = fmul fast <4 x float> %x, <float 3.0, float 3.0, float 3.0, float 3.0>113 %z = fmul fast <4 x float> %y, <float 4.0, float 4.0, float 4.0, float 4.0>114 ret <4 x float> %z115}116 117; CHECK: float 5118; CHECK: float 12119; CHECK: float 21120; CHECK: float 32121 122; We should be able to pre-multiply the two constant vectors.123define <4 x float> @fmul_v4f32_two_consts_no_splat(<4 x float> %x) {124; CHECK-LABEL: fmul_v4f32_two_consts_no_splat:125; CHECK: # %bb.0:126; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0127; CHECK-NEXT: retq128 %y = fmul fast <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>129 %z = fmul fast <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>130 ret <4 x float> %z131}132 133; Same as above, but reverse operands to make sure non-canonical form is also handled.134define <4 x float> @fmul_v4f32_two_consts_no_splat_non_canonical(<4 x float> %x) {135; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_non_canonical:136; CHECK: # %bb.0:137; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0138; CHECK-NEXT: retq139 %y = fmul fast <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0>, %x140 %z = fmul fast <4 x float> <float 5.0, float 6.0, float 7.0, float 8.0>, %y141 ret <4 x float> %z142}143 144; Node-level FMF and no function-level attributes.145 146define <4 x float> @fmul_v4f32_two_consts_no_splat_reassoc(<4 x float> %x) {147; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_reassoc:148; CHECK: # %bb.0:149; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0150; CHECK-NEXT: retq151 %y = fmul <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>152 %z = fmul reassoc <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>153 ret <4 x float> %z154}155 156; Multiplication by 2.0 is a special case because that gets converted to fadd x, x.157 158define <4 x float> @fmul_v4f32_two_consts_no_splat_reassoc_2(<4 x float> %x) {159; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_reassoc_2:160; CHECK: # %bb.0:161; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0162; CHECK-NEXT: retq163 %y = fadd <4 x float> %x, %x164 %z = fmul reassoc <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>165 ret <4 x float> %z166}167 168; CHECK: float 6169; CHECK: float 14170; CHECK: float 24171; CHECK: float 36172 173; More than one use of a constant multiply should not inhibit the optimization.174; Instead of a chain of 2 dependent mults, this test will have 2 independent mults.175define <4 x float> @fmul_v4f32_two_consts_no_splat_multiple_use(<4 x float> %x) {176; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_multiple_use:177; CHECK: # %bb.0:178; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0179; CHECK-NEXT: retq180 %y = fmul fast <4 x float> %x, <float 1.0, float 2.0, float 3.0, float 4.0>181 %z = fmul fast <4 x float> %y, <float 5.0, float 6.0, float 7.0, float 8.0>182 %a = fadd fast <4 x float> %y, %z183 ret <4 x float> %a184}185 186; PR22698 - http://llvm.org/bugs/show_bug.cgi?id=22698187; Make sure that we don't infinite loop swapping constants back and forth.188 189; CHECK: float 24190; CHECK: float 24191; CHECK: float 24192; CHECK: float 24193 194define <4 x float> @PR22698_splats(<4 x float> %a) {195; CHECK-LABEL: PR22698_splats:196; CHECK: # %bb.0:197; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0198; CHECK-NEXT: retq199 %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>200 %mul2 = fmul fast <4 x float> <float 4.0, float 4.0, float 4.0, float 4.0>, %mul1201 %mul3 = fmul fast <4 x float> %a, %mul2202 ret <4 x float> %mul3203}204 205; Same as above, but verify that non-splat vectors are handled correctly too.206 207; CHECK: float 45208; CHECK: float 120209; CHECK: float 231210; CHECK: float 384211 212define <4 x float> @PR22698_no_splats(<4 x float> %a) {213; CHECK-LABEL: PR22698_no_splats:214; CHECK: # %bb.0:215; CHECK-NEXT: mulps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0216; CHECK-NEXT: retq217 %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>218 %mul2 = fmul fast <4 x float> <float 9.0, float 10.0, float 11.0, float 12.0>, %mul1219 %mul3 = fmul fast <4 x float> %a, %mul2220 ret <4 x float> %mul3221}222 223define float @fmul_c2_c4_f32(float %x) {224; CHECK-LABEL: fmul_c2_c4_f32:225; CHECK: # %bb.0:226; CHECK-NEXT: mulss {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0227; CHECK-NEXT: retq228 %y = fmul fast float %x, 2.0229 %z = fmul fast float %y, 4.0230 ret float %z231}232 233define float @fmul_c3_c4_f32(float %x) {234; CHECK-LABEL: fmul_c3_c4_f32:235; CHECK: # %bb.0:236; CHECK-NEXT: mulss {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0237; CHECK-NEXT: retq238 %y = fmul fast float %x, 3.0239 %z = fmul fast float %y, 4.0240 ret float %z241}242 243define float @fmul_fneg_fneg_f32(float %x, float %y) {244; CHECK-LABEL: fmul_fneg_fneg_f32:245; CHECK: # %bb.0:246; CHECK-NEXT: mulss %xmm1, %xmm0247; CHECK-NEXT: retq248 %x.neg = fsub float -0.0, %x249 %y.neg = fsub float -0.0, %y250 %mul = fmul float %x.neg, %y.neg251 ret float %mul252}253 254define <4 x float> @fmul_fneg_fneg_v4f32(<4 x float> %x, <4 x float> %y) {255; CHECK-LABEL: fmul_fneg_fneg_v4f32:256; CHECK: # %bb.0:257; CHECK-NEXT: mulps %xmm1, %xmm0258; CHECK-NEXT: retq259 %x.neg = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %x260 %y.neg = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %y261 %mul = fmul <4 x float> %x.neg, %y.neg262 ret <4 x float> %mul263}264 265; PR47517 - this could crash if we create 'fmul x, 0.0' nodes266; that do not constant fold in a particular order.267 268define float @getNegatedExpression_crash(ptr %p) {269; CHECK-LABEL: getNegatedExpression_crash:270; CHECK: # %bb.0:271; CHECK-NEXT: movl $0, (%rdi)272; CHECK-NEXT: xorps %xmm0, %xmm0273; CHECK-NEXT: retq274 store float 0.0, ptr %p, align 1275 %real = load float, ptr %p, align 1276 %r2 = fmul fast float %real, %real277 %t1 = fmul fast float %real, 42.0278 %t2 = fmul fast float %real, %t1279 %mul_ac56 = fmul fast float %t2, %t1280 %mul_ac72 = fmul fast float %r2, %mul_ac56281 ret float %mul_ac72282}283