1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; RUN: llc < %s -mtriple=i686-- -mattr=+sse4.1 | FileCheck %s 3 4; Test that when we don't -enable-unsafe-fp-math, we don't do the optimization 5; -0 - (A - B) to (B - A) because A==B, -0 != 0 6 7define float @negfp(float %a, float %b) nounwind { 8; CHECK-LABEL: negfp: 9; CHECK: # %bb.0: # %entry 10; CHECK-NEXT: pushl %eax 11; CHECK-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero 12; CHECK-NEXT: subss {{[0-9]+}}(%esp), %xmm0 13; CHECK-NEXT: xorps {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0 14; CHECK-NEXT: movss %xmm0, (%esp) 15; CHECK-NEXT: flds (%esp) 16; CHECK-NEXT: popl %eax 17; CHECK-NEXT: retl 18entry: 19 %sub = fsub float %a, %b ; <float> [#uses=1] 20 %neg = fsub float -0.000000e+00, %sub ; <float> [#uses=1] 21 ret float %neg 22} 23 24; This may infinite loop if isNegatibleForFree and getNegatedExpression are conflicted. 25 26define double @negation_propagation(ptr %arg, double %arg1, double %arg2) nounwind { 27; CHECK-LABEL: negation_propagation: 28; CHECK: # %bb.0: 29; CHECK-NEXT: pushl %ebp 30; CHECK-NEXT: movl %esp, %ebp 31; CHECK-NEXT: andl $-8, %esp 32; CHECK-NEXT: subl $8, %esp 33; CHECK-NEXT: movsd {{.*#+}} xmm0 = [1.0E+0,0.0E+0] 34; CHECK-NEXT: divsd 12(%ebp), %xmm0 35; CHECK-NEXT: movsd {{.*#+}} xmm1 = mem[0],zero 36; CHECK-NEXT: mulsd %xmm0, %xmm1 37; CHECK-NEXT: movapd %xmm0, %xmm2 38; CHECK-NEXT: mulsd %xmm0, %xmm2 39; CHECK-NEXT: mulsd %xmm0, %xmm2 40; CHECK-NEXT: subsd %xmm2, %xmm1 41; CHECK-NEXT: movsd %xmm1, (%esp) 42; CHECK-NEXT: fldl (%esp) 43; CHECK-NEXT: movl %ebp, %esp 44; CHECK-NEXT: popl %ebp 45; CHECK-NEXT: retl 46 %t = fdiv double 1.0, %arg1 47 %t7 = fmul double %t, %arg2 48 %t10 = fneg double %t7 49 %t11 = fmul double %t, %t 50 %t13 = fsub double %t11, %t 51 %t14 = fneg double %t 52 %t15 = fmul double %t, %t14 53 %t16 = fmul double %t, %t15 54 %t18 = fadd double %t16, %t7 55 ret double %t18 56} 57 58; This would crash because the negated expression for %sub4 59; creates a new use of %sub1 and that alters the negated cost 60 61define float @fdiv_extra_use_changes_cost(float %a0, float %a1, float %a2) nounwind { 62; CHECK-LABEL: fdiv_extra_use_changes_cost: 63; CHECK: # %bb.0: 64; CHECK-NEXT: pushl %eax 65; CHECK-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero 66; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero 67; CHECK-NEXT: subss {{[0-9]+}}(%esp), %xmm1 68; CHECK-NEXT: movaps %xmm1, %xmm2 69; CHECK-NEXT: mulss %xmm0, %xmm2 70; CHECK-NEXT: subss %xmm1, %xmm0 71; CHECK-NEXT: divss %xmm2, %xmm0 72; CHECK-NEXT: movss %xmm0, (%esp) 73; CHECK-NEXT: flds (%esp) 74; CHECK-NEXT: popl %eax 75; CHECK-NEXT: retl 76 %sub1 = fsub fast float %a0, %a1 77 %mul2 = fmul fast float %sub1, %a2 78 %neg = fneg fast float %a0 79 %add3 = fadd fast float %a1, %neg 80 %sub4 = fadd fast float %add3, %a2 81 %div5 = fdiv fast float %sub4, %mul2 82 ret float %div5 83} 84 85; PR55758 - this is not -(-X) 86 87define <2 x i64> @fneg_mismatched_sizes(<4 x float> %x) { 88; CHECK-LABEL: fneg_mismatched_sizes: 89; CHECK: # %bb.0: 90; CHECK-NEXT: xorps {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0 91; CHECK-NEXT: xorps {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0 92; CHECK-NEXT: retl 93 %n = fneg <4 x float> %x 94 %b = bitcast <4 x float> %n to <2 x i64> 95 %r = xor <2 x i64> %b, <i64 -9223372036854775808, i64 -9223372036854775808> 96 ret <2 x i64> %r 97} 98