Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ void DAGTypeLegalizer::SoftenFloatResult(SDNode *N, unsigned ResNo) {
case ISD::EXTRACT_VECTOR_ELT:
R = SoftenFloatRes_EXTRACT_VECTOR_ELT(N, ResNo); break;
case ISD::FABS: R = SoftenFloatRes_FABS(N); break;
case ISD::FCANONICALIZE:
R = SoftenFloatRes_FCANONICALIZE(N); break;
case ISD::STRICT_FMINNUM:
case ISD::FMINNUM: R = SoftenFloatRes_FMINNUM(N); break;
case ISD::STRICT_FMAXNUM:
Expand Down Expand Up @@ -311,6 +313,17 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FABS(SDNode *N) {
return DAG.getNode(ISD::AND, SDLoc(N), NVT, Op, Mask);
}

SDValue DAGTypeLegalizer::SoftenFloatRes_FCANONICALIZE(SDNode *N) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code feels like a series of hacks to reuse existing Softening functions.

Can we do this instead. It's the code from LegalizeDAG with a BitConvertToInteger at the end.

SDValue DAGTypeLegalizer::SoftenFloatRes_FCANONICALIZE(SDNode *N) {                                           
  SDLoc dl(N);                                                                                                
                                                                                                              
  // This implements llvm.canonicalize.f* by multiplication with 1.0, as
  // suggested in
  // https://llvm.org/docs/LangRef.html#llvm-canonicalize-intrinsic.
  // It uses strict_fp operations even outside a strict_fp context in order
  // to guarantee that the canonicalization is not optimized away by later
  // passes. The result chain introduced by that is intentionally ignored
  // since no ordering requirement is intended here.

  // Create strict multiplication by 1.0.
  SDValue Operand = N->getOperand(0);
  EVT VT = Operand.getValueType();
  SDValue One = DAG.getConstantFP(1.0, dl, VT);
  SDValue Chain = DAG.getEntryNode();
  // Propagate existing flags on canonicalize, and additionally set
  // NoFPExcept.
  SDNodeFlags CanonicalizeFlags = N->getFlags();
  CanonicalizeFlags.setNoFPExcept(true);
  SDValue Mul = DAG.getNode(ISD::STRICT_FMUL, dl, {VT, MVT::Other},
                            {Chain, Operand, One}, CanonicalizeFlags);
  return BitConvertToInteger(Mul);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, thank you that's much better
you were right, I tried to bend the API to make it work like the other methods :)

SDLoc dl(N);
auto Node = DAG.getNode(ISD::FMINIMUMNUM, dl, N->getValueType(0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no auto

N->getOperand(0), N->getOperand(0));
return SoftenFloatRes_Binary(
Node.getNode(),
GetFPLibCall(N->getValueType(0), RTLIB::FMINIMUM_NUM_F32,
RTLIB::FMINIMUM_NUM_F64, RTLIB::FMINIMUM_NUM_F80,
RTLIB::FMINIMUM_NUM_F128, RTLIB::FMINIMUM_NUM_PPCF128));
}

SDValue DAGTypeLegalizer::SoftenFloatRes_FMINNUM(SDNode *N) {
if (SDValue SelCC = TLI.createSelectForFMINNUM_FMAXNUM(N, DAG))
return SoftenFloatRes_SELECT_CC(SelCC.getNode());
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
SDValue SoftenFloatRes_FASIN(SDNode *N);
SDValue SoftenFloatRes_FATAN(SDNode *N);
SDValue SoftenFloatRes_FATAN2(SDNode *N);
SDValue SoftenFloatRes_FCANONICALIZE(SDNode *N);
SDValue SoftenFloatRes_FMINNUM(SDNode *N);
SDValue SoftenFloatRes_FMAXNUM(SDNode *N);
SDValue SoftenFloatRes_FMINIMUMNUM(SDNode *N);
Expand Down
Loading