llvm.org GIT mirror llvm / e669c93
In various places throughout the code generator, there were special checks to avoid performing compile-time arithmetic on PPCDoubleDouble. Now that APFloat supports arithmetic on PPCDoubleDouble, those checks are no longer needed, and we can treat the type like any other. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166958 91177308-0d34-0410-b5e6-96231b3b80d8 Ulrich Weigand 7 years ago
6 changed file(s) with 69 addition(s) and 93 deletion(s). Raw diff Collapse all Expand all
11981198 /// have to duplicate its logic everywhere it's called.
11991199 bool isExactlyValue(double V) const {
12001200 bool ignored;
1201 // convert is not supported on this type
1202 if (&Value->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
1203 return false;
12041201 APFloat Tmp(V);
12051202 Tmp.convert(Value->getValueAPF().getSemantics(),
12061203 APFloat::rmNearestTiesToEven, &ignored);
281281
282282 bool isExactlyValue(double V) const {
283283 bool ignored;
284 // convert is not supported on this type
285 if (&Val.getSemantics() == &APFloat::PPCDoubleDouble)
286 return false;
287284 APFloat FV(V);
288285 FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored);
289286 return isExactlyValue(FV);
392392 const TargetLowering &TLI,
393393 const TargetOptions *Options,
394394 unsigned Depth = 0) {
395 // No compile time optimizations on this type.
396 if (Op.getValueType() == MVT::ppcf128)
397 return 0;
398
399395 // fneg is removable even if it has multiple uses.
400396 if (Op.getOpcode() == ISD::FNEG) return 2;
401397
57045700 }
57055701
57065702 // fold (fadd c1, c2) -> c1 + c2
5707 if (N0CFP && N1CFP && VT != MVT::ppcf128)
5703 if (N0CFP && N1CFP)
57085704 return DAG.getNode(ISD::FADD, N->getDebugLoc(), VT, N0, N1);
57095705 // canonicalize constant to RHS
57105706 if (N0CFP && !N1CFP)
58915887 }
58925888
58935889 // fold (fsub c1, c2) -> c1-c2
5894 if (N0CFP && N1CFP && VT != MVT::ppcf128)
5890 if (N0CFP && N1CFP)
58955891 return DAG.getNode(ISD::FSUB, N->getDebugLoc(), VT, N0, N1);
58965892 // fold (fsub A, 0) -> A
58975893 if (DAG.getTarget().Options.UnsafeFPMath &&
59835979 }
59845980
59855981 // fold (fmul c1, c2) -> c1*c2
5986 if (N0CFP && N1CFP && VT != MVT::ppcf128)
5982 if (N0CFP && N1CFP)
59875983 return DAG.getNode(ISD::FMUL, N->getDebugLoc(), VT, N0, N1);
59885984 // canonicalize constant to RHS
59895985 if (N0CFP && !N1CFP)
61206116 }
61216117
61226118 // fold (fdiv c1, c2) -> c1/c2
6123 if (N0CFP && N1CFP && VT != MVT::ppcf128)
6119 if (N0CFP && N1CFP)
61246120 return DAG.getNode(ISD::FDIV, N->getDebugLoc(), VT, N0, N1);
61256121
61266122 // fold (fdiv X, c2) -> fmul X, 1/c2 if losing precision is acceptable.
6127 if (N1CFP && VT != MVT::ppcf128 && DAG.getTarget().Options.UnsafeFPMath) {
6123 if (N1CFP && DAG.getTarget().Options.UnsafeFPMath) {
61286124 // Compute the reciprocal 1.0 / c2.
61296125 APFloat N1APF = N1CFP->getValueAPF();
61306126 APFloat Recip(N1APF.getSemantics(), 1); // 1.0
61676163 EVT VT = N->getValueType(0);
61686164
61696165 // fold (frem c1, c2) -> fmod(c1,c2)
6170 if (N0CFP && N1CFP && VT != MVT::ppcf128)
6166 if (N0CFP && N1CFP)
61716167 return DAG.getNode(ISD::FREM, N->getDebugLoc(), VT, N0, N1);
61726168
61736169 return SDValue();
61806176 ConstantFPSDNode *N1CFP = dyn_cast(N1);
61816177 EVT VT = N->getValueType(0);
61826178
6183 if (N0CFP && N1CFP && VT != MVT::ppcf128) // Constant fold
6179 if (N0CFP && N1CFP) // Constant fold
61846180 return DAG.getNode(ISD::FCOPYSIGN, N->getDebugLoc(), VT, N0, N1);
61856181
61866182 if (N1CFP) {
62306226 EVT OpVT = N0.getValueType();
62316227
62326228 // fold (sint_to_fp c1) -> c1fp
6233 if (N0C && OpVT != MVT::ppcf128 &&
6229 if (N0C &&
62346230 // ...but only if the target supports immediate floating-point values
62356231 (!LegalOperations ||
62366232 TLI.isOperationLegalOrCustom(llvm::ISD::ConstantFP, VT)))
62876283 EVT OpVT = N0.getValueType();
62886284
62896285 // fold (uint_to_fp c1) -> c1fp
6290 if (N0C && OpVT != MVT::ppcf128 &&
6286 if (N0C &&
62916287 // ...but only if the target supports immediate floating-point values
62926288 (!LegalOperations ||
62936289 TLI.isOperationLegalOrCustom(llvm::ISD::ConstantFP, VT)))
63426338 EVT VT = N->getValueType(0);
63436339
63446340 // fold (fp_to_uint c1fp) -> c1
6345 if (N0CFP && VT != MVT::ppcf128)
6341 if (N0CFP)
63466342 return DAG.getNode(ISD::FP_TO_UINT, N->getDebugLoc(), VT, N0);
63476343
63486344 return SDValue();
63556351 EVT VT = N->getValueType(0);
63566352
63576353 // fold (fp_round c1fp) -> c1fp
6358 if (N0CFP && N0.getValueType() != MVT::ppcf128)
6354 if (N0CFP)
63596355 return DAG.getNode(ISD::FP_ROUND, N->getDebugLoc(), VT, N0, N1);
63606356
63616357 // fold (fp_round (fp_extend x)) -> x
64096405 return SDValue();
64106406
64116407 // fold (fp_extend c1fp) -> c1fp
6412 if (N0CFP && VT != MVT::ppcf128)
6408 if (N0CFP)
64136409 return DAG.getNode(ISD::FP_EXTEND, N->getDebugLoc(), VT, N0);
64146410
64156411 // Turn fp_extend(fp_round(X, 1)) -> x since the fp_round doesn't affect the
64966492 EVT VT = N->getValueType(0);
64976493
64986494 // fold (fceil c1) -> fceil(c1)
6499 if (N0CFP && VT != MVT::ppcf128)
6495 if (N0CFP)
65006496 return DAG.getNode(ISD::FCEIL, N->getDebugLoc(), VT, N0);
65016497
65026498 return SDValue();
65086504 EVT VT = N->getValueType(0);
65096505
65106506 // fold (ftrunc c1) -> ftrunc(c1)
6511 if (N0CFP && VT != MVT::ppcf128)
6507 if (N0CFP)
65126508 return DAG.getNode(ISD::FTRUNC, N->getDebugLoc(), VT, N0);
65136509
65146510 return SDValue();
65206516 EVT VT = N->getValueType(0);
65216517
65226518 // fold (ffloor c1) -> ffloor(c1)
6523 if (N0CFP && VT != MVT::ppcf128)
6519 if (N0CFP)
65246520 return DAG.getNode(ISD::FFLOOR, N->getDebugLoc(), VT, N0);
65256521
65266522 return SDValue();
65376533 }
65386534
65396535 // fold (fabs c1) -> fabs(c1)
6540 if (N0CFP && VT != MVT::ppcf128)
6536 if (N0CFP)
65416537 return DAG.getNode(ISD::FABS, N->getDebugLoc(), VT, N0);
65426538 // fold (fabs (fabs x)) -> (fabs x)
65436539 if (N0.getOpcode() == ISD::FABS)
9090 const APFloat& Val) {
9191 assert(VT.isFloatingPoint() && "Can only convert between FP types");
9292
93 // PPC long double cannot be converted to any other type.
94 if (VT == MVT::ppcf128 ||
95 &Val.getSemantics() == &APFloat::PPCDoubleDouble)
96 return false;
97
9893 // convert modifies in place, so make a copy.
9994 APFloat Val2 = APFloat(Val);
10095 bool losesInfo;
16111606 }
16121607 if (ConstantFPSDNode *N1C = dyn_cast(N1.getNode())) {
16131608 if (ConstantFPSDNode *N2C = dyn_cast(N2.getNode())) {
1614 // No compile time operations on this type yet.
1615 if (N1C->getValueType(0) == MVT::ppcf128)
1616 return SDValue();
1617
16181609 APFloat::cmpResult R = N1C->getValueAPF().compare(N2C->getValueAPF());
16191610 switch (Cond) {
16201611 default: break;
24462437 return getConstant(Val.zextOrTrunc(VT.getSizeInBits()), VT);
24472438 case ISD::UINT_TO_FP:
24482439 case ISD::SINT_TO_FP: {
2449 // No compile time operations on ppcf128.
2450 if (VT == MVT::ppcf128) break;
24512440 APFloat apf(APInt::getNullValue(VT.getSizeInBits()));
24522441 (void)apf.convertFromAPInt(Val,
24532442 Opcode==ISD::SINT_TO_FP,
24762465 // Constant fold unary operations with a floating point constant operand.
24772466 if (ConstantFPSDNode *C = dyn_cast(Operand.getNode())) {
24782467 APFloat V = C->getValueAPF(); // make copy
2479 if (VT != MVT::ppcf128 && Operand.getValueType() != MVT::ppcf128) {
2480 switch (Opcode) {
2481 case ISD::FNEG:
2482 V.changeSign();
2468 switch (Opcode) {
2469 case ISD::FNEG:
2470 V.changeSign();
2471 return getConstantFP(V, VT);
2472 case ISD::FABS:
2473 V.clearSign();
2474 return getConstantFP(V, VT);
2475 case ISD::FCEIL: {
2476 APFloat::opStatus fs = V.roundToIntegral(APFloat::rmTowardPositive);
2477 if (fs == APFloat::opOK || fs == APFloat::opInexact)
24832478 return getConstantFP(V, VT);
2484 case ISD::FABS:
2485 V.clearSign();
2479 break;
2480 }
2481 case ISD::FTRUNC: {
2482 APFloat::opStatus fs = V.roundToIntegral(APFloat::rmTowardZero);
2483 if (fs == APFloat::opOK || fs == APFloat::opInexact)
24862484 return getConstantFP(V, VT);
2487 case ISD::FCEIL: {
2488 APFloat::opStatus fs = V.roundToIntegral(APFloat::rmTowardPositive);
2489 if (fs == APFloat::opOK || fs == APFloat::opInexact)
2490 return getConstantFP(V, VT);
2485 break;
2486 }
2487 case ISD::FFLOOR: {
2488 APFloat::opStatus fs = V.roundToIntegral(APFloat::rmTowardNegative);
2489 if (fs == APFloat::opOK || fs == APFloat::opInexact)
2490 return getConstantFP(V, VT);
2491 break;
2492 }
2493 case ISD::FP_EXTEND: {
2494 bool ignored;
2495 // This can return overflow, underflow, or inexact; we don't care.
2496 // FIXME need to be more flexible about rounding mode.
2497 (void)V.convert(*EVTToAPFloatSemantics(VT),
2498 APFloat::rmNearestTiesToEven, &ignored);
2499 return getConstantFP(V, VT);
2500 }
2501 case ISD::FP_TO_SINT:
2502 case ISD::FP_TO_UINT: {
2503 integerPart x[2];
2504 bool ignored;
2505 assert(integerPartWidth >= 64);
2506 // FIXME need to be more flexible about rounding mode.
2507 APFloat::opStatus s = V.convertToInteger(x, VT.getSizeInBits(),
2508 Opcode==ISD::FP_TO_SINT,
2509 APFloat::rmTowardZero, &ignored);
2510 if (s==APFloat::opInvalidOp) // inexact is OK, in fact usual
24912511 break;
2492 }
2493 case ISD::FTRUNC: {
2494 APFloat::opStatus fs = V.roundToIntegral(APFloat::rmTowardZero);
2495 if (fs == APFloat::opOK || fs == APFloat::opInexact)
2496 return getConstantFP(V, VT);
2497 break;
2498 }
2499 case ISD::FFLOOR: {
2500 APFloat::opStatus fs = V.roundToIntegral(APFloat::rmTowardNegative);
2501 if (fs == APFloat::opOK || fs == APFloat::opInexact)
2502 return getConstantFP(V, VT);
2503 break;
2504 }
2505 case ISD::FP_EXTEND: {
2506 bool ignored;
2507 // This can return overflow, underflow, or inexact; we don't care.
2508 // FIXME need to be more flexible about rounding mode.
2509 (void)V.convert(*EVTToAPFloatSemantics(VT),
2510 APFloat::rmNearestTiesToEven, &ignored);
2511 return getConstantFP(V, VT);
2512 }
2513 case ISD::FP_TO_SINT:
2514 case ISD::FP_TO_UINT: {
2515 integerPart x[2];
2516 bool ignored;
2517 assert(integerPartWidth >= 64);
2518 // FIXME need to be more flexible about rounding mode.
2519 APFloat::opStatus s = V.convertToInteger(x, VT.getSizeInBits(),
2520 Opcode==ISD::FP_TO_SINT,
2521 APFloat::rmTowardZero, &ignored);
2522 if (s==APFloat::opInvalidOp) // inexact is OK, in fact usual
2523 break;
2524 APInt api(VT.getSizeInBits(), x);
2525 return getConstant(api, VT);
2526 }
2527 case ISD::BITCAST:
2528 if (VT == MVT::i32 && C->getValueType(0) == MVT::f32)
2529 return getConstant((uint32_t)V.bitcastToAPInt().getZExtValue(), VT);
2530 else if (VT == MVT::i64 && C->getValueType(0) == MVT::f64)
2531 return getConstant(V.bitcastToAPInt().getZExtValue(), VT);
2532 break;
2533 }
2512 APInt api(VT.getSizeInBits(), x);
2513 return getConstant(api, VT);
2514 }
2515 case ISD::BITCAST:
2516 if (VT == MVT::i32 && C->getValueType(0) == MVT::f32)
2517 return getConstant((uint32_t)V.bitcastToAPInt().getZExtValue(), VT);
2518 else if (VT == MVT::i64 && C->getValueType(0) == MVT::f64)
2519 return getConstant(V.bitcastToAPInt().getZExtValue(), VT);
2520 break;
25342521 }
25352522 }
25362523
30513038 // Cannonicalize constant to RHS if commutative
30523039 std::swap(N1CFP, N2CFP);
30533040 std::swap(N1, N2);
3054 } else if (N2CFP && VT != MVT::ppcf128) {
3041 } else if (N2CFP) {
30553042 APFloat V1 = N1CFP->getValueAPF(), V2 = N2CFP->getValueAPF();
30563043 APFloat::opStatus s;
30573044 switch (Opcode) {
219219 /// ConvertToSInt - Convert APF to an integer, if possible.
220220 static bool ConvertToSInt(const APFloat &APF, int64_t &IntVal) {
221221 bool isExact = false;
222 if (&APF.getSemantics() == &APFloat::PPCDoubleDouble)
223 return false;
224222 // See if we can convert this to an int64_t
225223 uint64_t UIntVal;
226224 if (APF.convertToInteger(&UIntVal, 64, true, APFloat::rmTowardZero,
None ; RUN: llc < %s -march=ppc64 | grep __floatditf
0 ; RUN: llc < %s -march=ppc64 | FileCheck %s
1 ; CHECK-NOT: __floatditf
12
23 define i64 @__fixunstfdi(ppc_fp128 %a) nounwind {
34 entry: