[PATCH] DAGCombine: constant fold FMA

hfinkel at anl.gov hfinkel at anl.gov
Fri Jan 9 23:27:26 PST 2015


I think you're not understanding the code, but feel free to add a comment making it more clear what is going on. When you call DAG.getNode, you end up in this code:

  SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, EVT VT,
                                SDValue N1, SDValue N2, SDValue N3) {
  // Perform various simplifications.
  ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.getNode());
  switch (Opcode) {
  case ISD::FMA: {
    ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1);
    ConstantFPSDNode *N2CFP = dyn_cast<ConstantFPSDNode>(N2);
    ConstantFPSDNode *N3CFP = dyn_cast<ConstantFPSDNode>(N3);
    if (N1CFP && N2CFP && N3CFP) {
      APFloat  V1 = N1CFP->getValueAPF();
      const APFloat &V2 = N2CFP->getValueAPF();
      const APFloat &V3 = N3CFP->getValueAPF();
      APFloat::opStatus s =
        V1.fusedMultiplyAdd(V2, V3, APFloat::rmNearestTiesToEven);
      if (s != APFloat::opInvalidOp)
        return getConstantFP(V1, VT);
    }
    break;
  }

and that will constant-fold the node when possible.


http://reviews.llvm.org/D6912

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list