@@ -430,50 +430,48 @@ SDValue SelectionDAGLegalize::OptimizeFloatStore(StoreSDNode* ST) {
430430 if (Value.getOpcode () == ISD::TargetConstantFP)
431431 return SDValue ();
432432
433- ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Value);
434- if (!CFP)
435- return SDValue ();
436-
437433 if (!TLI.canUseIntLoadStoreForFloatValues ())
438434 return SDValue ();
439435
440- EVT FloatTy = CFP->getValueType (0 );
441- if (FloatTy == MVT::f32 && TLI.isTypeLegal (MVT::i32 )) {
442- SDValue Con =
443- DAG.getConstant (CFP->getValueAPF ().bitcastToAPInt ().zextOrTrunc (32 ),
444- SDLoc (CFP), MVT::i32 );
445- return DAG.getStore (Chain, dl, Con, Ptr, ST->getPointerInfo (),
446- ST->getOriginalAlign (), MMOFlags, AAInfo);
447- }
448-
449- if (FloatTy == MVT::f64 && !TLI.isFPImmLegal (CFP->getValueAPF (), MVT::f64 )) {
450- // If this target supports 64-bit registers, do a single 64-bit store.
451- if (TLI.isTypeLegal (MVT::i64 )) {
452- SDValue Con =
453- DAG.getConstant (CFP->getValueAPF ().bitcastToAPInt ().zextOrTrunc (64 ),
454- SDLoc (CFP), MVT::i64 );
436+ if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Value)) {
437+ if (CFP->getValueType (0 ) == MVT::f32 &&
438+ TLI.isTypeLegal (MVT::i32 )) {
439+ SDValue Con = DAG.getConstant (CFP->getValueAPF ().
440+ bitcastToAPInt ().zextOrTrunc (32 ),
441+ SDLoc (CFP), MVT::i32 );
455442 return DAG.getStore (Chain, dl, Con, Ptr, ST->getPointerInfo (),
456443 ST->getOriginalAlign (), MMOFlags, AAInfo);
457444 }
458445
459- if (TLI.isTypeLegal (MVT::i32 ) && !ST->isVolatile ()) {
460- // Otherwise, if the target supports 32-bit registers, use 2 32-bit
461- // stores. If the target supports neither 32- nor 64-bits, this xform is
462- // certainly not worth it.
463- const APInt &IntVal = CFP->getValueAPF ().bitcastToAPInt ();
464- SDValue Lo = DAG.getConstant (IntVal.trunc (32 ), dl, MVT::i32 );
465- SDValue Hi = DAG.getConstant (IntVal.lshr (32 ).trunc (32 ), dl, MVT::i32 );
466- if (DAG.getDataLayout ().isBigEndian ())
467- std::swap (Lo, Hi);
468-
469- Lo = DAG.getStore (Chain, dl, Lo, Ptr, ST->getPointerInfo (),
470- ST->getOriginalAlign (), MMOFlags, AAInfo);
471- Ptr = DAG.getMemBasePlusOffset (Ptr, TypeSize::getFixed (4 ), dl);
472- Hi = DAG.getStore (Chain, dl, Hi, Ptr,
473- ST->getPointerInfo ().getWithOffset (4 ),
474- ST->getOriginalAlign (), MMOFlags, AAInfo);
475-
476- return DAG.getNode (ISD::TokenFactor, dl, MVT::Other, Lo, Hi);
446+ if (CFP->getValueType (0 ) == MVT::f64 &&
447+ !TLI.isFPImmLegal (CFP->getValueAPF (), MVT::f64 )) {
448+ // If this target supports 64-bit registers, do a single 64-bit store.
449+ if (TLI.isTypeLegal (MVT::i64 )) {
450+ SDValue Con = DAG.getConstant (CFP->getValueAPF ().bitcastToAPInt ().
451+ zextOrTrunc (64 ), SDLoc (CFP), MVT::i64 );
452+ return DAG.getStore (Chain, dl, Con, Ptr, ST->getPointerInfo (),
453+ ST->getOriginalAlign (), MMOFlags, AAInfo);
454+ }
455+
456+ if (TLI.isTypeLegal (MVT::i32 ) && !ST->isVolatile ()) {
457+ // Otherwise, if the target supports 32-bit registers, use 2 32-bit
458+ // stores. If the target supports neither 32- nor 64-bits, this
459+ // xform is certainly not worth it.
460+ const APInt &IntVal = CFP->getValueAPF ().bitcastToAPInt ();
461+ SDValue Lo = DAG.getConstant (IntVal.trunc (32 ), dl, MVT::i32 );
462+ SDValue Hi = DAG.getConstant (IntVal.lshr (32 ).trunc (32 ), dl, MVT::i32 );
463+ if (DAG.getDataLayout ().isBigEndian ())
464+ std::swap (Lo, Hi);
465+
466+ Lo = DAG.getStore (Chain, dl, Lo, Ptr, ST->getPointerInfo (),
467+ ST->getOriginalAlign (), MMOFlags, AAInfo);
468+ Ptr = DAG.getMemBasePlusOffset (Ptr, TypeSize::getFixed (4 ), dl);
469+ Hi = DAG.getStore (Chain, dl, Hi, Ptr,
470+ ST->getPointerInfo ().getWithOffset (4 ),
471+ ST->getOriginalAlign (), MMOFlags, AAInfo);
472+
473+ return DAG.getNode (ISD::TokenFactor, dl, MVT::Other, Lo, Hi);
474+ }
477475 }
478476 }
479477 return SDValue ();
0 commit comments