# Changeset View

Changeset View

# Standalone View

Standalone View

# llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

- This file is larger than 256 KB, so syntax highlighting is disabled by default.

Show First 20 Lines • Show All 11565 Lines • ▼ Show 20 Line(s) | 11522 | SDValue DAGCombiner::visitFCOPYSIGN(SDNode *N) { | |||
---|---|---|---|---|---|

11566 | return SDValue(); | 11566 | return SDValue(); | ||

11567 | } | 11567 | } | ||

11568 | 11568 | | |||

11569 | SDValue DAGCombiner::visitFPOW(SDNode *N) { | 11569 | SDValue DAGCombiner::visitFPOW(SDNode *N) { | ||

11570 | ConstantFPSDNode *ExponentC = isConstOrConstSplatFP(N->getOperand(1)); | 11570 | ConstantFPSDNode *ExponentC = isConstOrConstSplatFP(N->getOperand(1)); | ||

11571 | if (!ExponentC) | 11571 | if (!ExponentC) | ||

11572 | return SDValue(); | 11572 | return SDValue(); | ||

11573 | 11573 | | |||

11574 | // Try to convert x ** (1/3) into cube root. | ||||

11575 | // TODO: Handle the various flavors of long double. | ||||

11576 | // TODO: Since we're approximating, we don't need an exact 1/3 exponent. | ||||

11577 | // Some range near 1/3 should be fine. | ||||

11578 | EVT VT = N->getValueType(0); | ||||

11579 | if ((VT == MVT::f32 && ExponentC->getValueAPF().isExactlyValue(1.0f/3.0f)) || | ||||

11580 | (VT == MVT::f64 && ExponentC->getValueAPF().isExactlyValue(1.0/3.0))) { | ||||

11581 | // pow(-0.0, 1/3) = +0.0; cbrt(-0.0) = -0.0. | ||||

11582 | // pow(-inf, 1/3) = +inf; cbrt(-inf) = -inf. | ||||

11583 | // pow(-val, 1/3) = nan; cbrt(-val) = -num. | ||||

11584 | // For regular numbers, rounding may cause the results to differ. | ||||

11585 | // Therefore, we require { nsz ninf nnan afn } for this transform. | ||||

11586 | // TODO: We could select out the special cases if we don't have nsz/ninf. | ||||

11587 | SDNodeFlags Flags = N->getFlags(); | ||||

11588 | if (!Flags.hasNoSignedZeros() || !Flags.hasNoInfs() || !Flags.hasNoNaNs() || | ||||

11589 | !Flags.hasApproximateFuncs()) | ||||

11590 | return SDValue(); | ||||

11591 | | ||||

11592 | // Do not create a cbrt() libcall if the target does not have it, and do not | ||||

11593 | // turn a pow that has lowering support into a cbrt() libcall. | ||||

11594 | if (!DAG.getLibInfo().has(LibFunc_cbrt) || | ||||

11595 | (!DAG.getTargetLoweringInfo().isOperationExpand(ISD::FPOW, VT) && | ||||

11596 | DAG.getTargetLoweringInfo().isOperationExpand(ISD::FCBRT, VT))) | ||||

11597 | return SDValue(); | ||||

11598 | | ||||

11599 | return DAG.getNode(ISD::FCBRT, SDLoc(N), VT, N->getOperand(0), Flags); | ||||

11600 | } | ||||

11601 | | ||||

11574 | // Try to convert x ** (1/4) into square roots. | 11602 | // Try to convert x ** (1/4) into square roots. | ||

11575 | // x ** (1/2) is canonicalized to sqrt, so we do not bother with that case. | 11603 | // x ** (1/2) is canonicalized to sqrt, so we do not bother with that case. | ||

11576 | // TODO: This could be extended (using a target hook) to handle smaller | 11604 | // TODO: This could be extended (using a target hook) to handle smaller | ||

11577 | // power-of-2 fractional exponents. | 11605 | // power-of-2 fractional exponents. | ||

11578 | if (ExponentC->getValueAPF().isExactlyValue(0.25)) { | 11606 | if (ExponentC->getValueAPF().isExactlyValue(0.25)) { | ||

11579 | // pow(-0.0, 0.25) = +0.0; sqrt(sqrt(-0.0)) = -0.0. | 11607 | // pow(-0.0, 0.25) = +0.0; sqrt(sqrt(-0.0)) = -0.0. | ||

11580 | // pow(-inf, 0.25) = +inf; sqrt(sqrt(-inf)) = NaN. | 11608 | // pow(-inf, 0.25) = +inf; sqrt(sqrt(-inf)) = NaN. | ||

11581 | // For regular numbers, rounding may cause the results to differ. | 11609 | // For regular numbers, rounding may cause the results to differ. | ||

11582 | // Therefore, we require { nsz ninf afn } for this transform. | 11610 | // Therefore, we require { nsz ninf afn } for this transform. | ||

11583 | // TODO: We could select out the special cases if we don't have nsz/ninf. | 11611 | // TODO: We could select out the special cases if we don't have nsz/ninf. | ||

11584 | SDNodeFlags Flags = N->getFlags(); | 11612 | SDNodeFlags Flags = N->getFlags(); | ||

11585 | if (!Flags.hasNoSignedZeros() || !Flags.hasNoInfs() || | 11613 | if (!Flags.hasNoSignedZeros() || !Flags.hasNoInfs() || | ||

11586 | !Flags.hasApproximateFuncs()) | 11614 | !Flags.hasApproximateFuncs()) | ||

11587 | return SDValue(); | 11615 | return SDValue(); | ||

11588 | 11616 | | |||

11589 | // Don't double the number of libcalls. We are trying to inline fast code. | 11617 | // Don't double the number of libcalls. We are trying to inline fast code. | ||

11590 | EVT VT = N->getValueType(0); | | |||

11591 | if (!DAG.getTargetLoweringInfo().isOperationLegalOrCustom(ISD::FSQRT, VT)) | 11618 | if (!DAG.getTargetLoweringInfo().isOperationLegalOrCustom(ISD::FSQRT, VT)) | ||

11592 | return SDValue(); | 11619 | return SDValue(); | ||

11593 | 11620 | | |||

11594 | // Assume that libcalls are the smallest code. | 11621 | // Assume that libcalls are the smallest code. | ||

11595 | // TODO: This restriction should probably be lifted for vectors. | 11622 | // TODO: This restriction should probably be lifted for vectors. | ||

11596 | if (DAG.getMachineFunction().getFunction().optForSize()) | 11623 | if (DAG.getMachineFunction().getFunction().optForSize()) | ||

11597 | return SDValue(); | 11624 | return SDValue(); | ||

11598 | 11625 | | |||

▲ Show 20 Lines • Show All 7203 Lines • Show Last 20 Lines |