llvm.org GIT mirror llvm / 607ebde
Add a few more simple fast-math constant propagations and cancellations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167200 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 7 years ago
2 changed file(s) with 38 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
57285728 DAG.getNode(ISD::FADD, N->getDebugLoc(), VT,
57295729 N0.getOperand(1), N1));
57305730
5731 // If allow, fold (fadd (fneg x), x) -> 0.0
5732 if (DAG.getTarget().Options.UnsafeFPMath &&
5733 N0.getOpcode() == ISD::FNEG && N0.getOperand(0) == N1) {
5734 return DAG.getConstantFP(0.0, VT);
5735 }
5736
5737 // If allow, fold (fadd x, (fneg x)) -> 0.0
5738 if (DAG.getTarget().Options.UnsafeFPMath &&
5739 N1.getOpcode() == ISD::FNEG && N1.getOperand(0) == N0) {
5740 return DAG.getConstantFP(0.0, VT);
5741 }
5742
57315743 // In unsafe math mode, we can fold chains of FADD's of the same value
57325744 // into multiplications. This transform is not safe in general because
57335745 // we are reducing the number of rounding steps.
60376049 EVT VT = N->getValueType(0);
60386050 DebugLoc dl = N->getDebugLoc();
60396051
6052 if (DAG.getTarget().Options.UnsafeFPMath) {
6053 if (N0CFP && N0CFP->isZero())
6054 return N2;
6055 if (N1CFP && N1CFP->isZero())
6056 return N2;
6057 }
60406058 if (N0CFP && N0CFP->isExactlyValue(1.0))
60416059 return DAG.getNode(ISD::FADD, N->getDebugLoc(), VT, N1, N2);
60426060 if (N1CFP && N1CFP->isExactlyValue(1.0))
3434 ret float %r
3535 }
3636
37 ; CHECK: test4
38 define float @test4(float %a) {
39 ; CHECK-NOT: fma
40 ; CHECK-NOT mul
41 ; CHECK-NOT: add
42 ; CHECK: ret
43 %t1 = fmul float %a, 0.0
44 %t2 = fadd float %a, %t1
45 ret float %t2
46 }
47
48 ; CHECK: test5
49 define float @test5(float %a) {
50 ; CHECK-NOT: add
51 ; CHECK: vxorps
52 ; CHECK: ret
53 %t1 = fsub float -0.0, %a
54 %t2 = fadd float %a, %t1
55 ret float %t2
56 }