@@ -263,19 +263,24 @@ SelectionDAGLegalize::ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP) {
263263 (VT == MVT::f64 ) ? MVT::i64 : MVT::i32 );
264264 }
265265
266+ APFloat APF = CFP->getValueAPF ();
266267 EVT OrigVT = VT;
267268 EVT SVT = VT;
268- while (SVT != MVT::f32 && SVT != MVT::f16 ) {
269- SVT = (MVT::SimpleValueType)(SVT.getSimpleVT ().SimpleTy - 1 );
270- if (ConstantFPSDNode::isValueValidForType (SVT, CFP->getValueAPF ()) &&
271- // Only do this if the target has a native EXTLOAD instruction from
272- // smaller type.
273- TLI.isLoadExtLegal (ISD::EXTLOAD, OrigVT, SVT) &&
274- TLI.ShouldShrinkFPConstant (OrigVT)) {
275- Type *SType = SVT.getTypeForEVT (*DAG.getContext ());
276- LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc (LLVMC, SType));
277- VT = SVT;
278- Extend = true ;
269+ // We don't want to shrink SNaNs. Converting the SNaN back to its real type
270+ // can cause it to be changed into a QNaN on some platforms (e.g. on SystemZ).
271+ if (!APF.isSignaling ()) {
272+ while (SVT != MVT::f32 && SVT != MVT::f16 ) {
273+ SVT = (MVT::SimpleValueType)(SVT.getSimpleVT ().SimpleTy - 1 );
274+ if (ConstantFPSDNode::isValueValidForType (SVT, APF) &&
275+ // Only do this if the target has a native EXTLOAD instruction from
276+ // smaller type.
277+ TLI.isLoadExtLegal (ISD::EXTLOAD, OrigVT, SVT) &&
278+ TLI.ShouldShrinkFPConstant (OrigVT)) {
279+ Type *SType = SVT.getTypeForEVT (*DAG.getContext ());
280+ LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc (LLVMC, SType));
281+ VT = SVT;
282+ Extend = true ;
283+ }
279284 }
280285 }
281286
0 commit comments