Index: include/llvm/CodeGen/SelectionDAGNodes.h =================================================================== --- include/llvm/CodeGen/SelectionDAGNodes.h +++ include/llvm/CodeGen/SelectionDAGNodes.h @@ -378,15 +378,20 @@ AllowContract(false), ApproximateFuncs(false), AllowReassociation(false) {} + /// Propagate the fast-math-flags from IR FastMathFlags + void copyFMF(FastMathFlags FMF) { + setNoNaNs(FMF.noNaNs()); + setNoInfs(FMF.noInfs()); + setNoSignedZeros(FMF.noSignedZeros()); + setAllowReciprocal(FMF.allowReciprocal()); + setAllowContract(FMF.allowContract()); + setApproximateFuncs(FMF.approxFunc()); + setAllowReassociation(FMF.allowReassoc()); + } + /// Propagate the fast-math-flags from an IR FPMathOperator. void copyFMF(const FPMathOperator &FPMO) { - setNoNaNs(FPMO.hasNoNaNs()); - setNoInfs(FPMO.hasNoInfs()); - setNoSignedZeros(FPMO.hasNoSignedZeros()); - setAllowReciprocal(FPMO.hasAllowReciprocal()); - setAllowContract(FPMO.hasAllowContract()); - setApproximateFuncs(FPMO.hasApproxFunc()); - setAllowReassociation(FPMO.hasAllowReassoc()); + copyFMF(FPMO.getFastMathFlags()); } /// Sets the state of the flags to the defined state. Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1088,8 +1088,10 @@ IncomingFlags.copyFMF(*FPMO); if (!Node->getFlags().isDefined()) Node->setFlags(IncomingFlags); +#if 0 else Node->intersectFlagsWith(IncomingFlags); +#endif } } @@ -2946,6 +2948,7 @@ auto BaseOps = {Cond}; ISD::NodeType OpCode = Cond.getValueType().isVector() ? ISD::VSELECT : ISD::SELECT; + SDNodeFlags Flags; // Min/max matching is only viable if all output VTs are the same. if (is_splat(ValueVTs)) { @@ -2967,6 +2970,8 @@ Value *LHS, *RHS; auto SPR = matchSelectPattern(const_cast(&I), LHS, RHS); + Flags.copyFMF(SPR.FMF); + ISD::NodeType Opc = ISD::DELETED_NODE; switch (SPR.Flavor) { case SPF_UMAX: Opc = ISD::UMAX; break; @@ -3031,7 +3036,7 @@ Ops.push_back(SDValue(RHSVal.getNode(), RHSVal.getResNo() + i)); Values[i] = DAG.getNode(OpCode, getCurSDLoc(), LHSVal.getNode()->getValueType(LHSVal.getResNo()+i), - Ops); + Ops, Flags); } setValue(&I, DAG.getNode(ISD::MERGE_VALUES, getCurSDLoc(),