Skip to content

Commit a9ffb71

Browse files
authored
[RISCV] Don't promote f16 FNEG/FABS with Zfhmin/Zhinxmin. (llvm#106474)
fneg/fabs are not supposed to canonicalize nans. Promoting to f32 will go through an fp_extend which will canonicalize. The generic Promote handler needs to be removed from LegalizeDAG. We need to use integer bit manip to clear the bit instead. Unfortunately, this is going through the stack due to i16 not being a legal type. Fixing that will require custom legalization or some other generic SelectionDAG change.
1 parent b5a1b45 commit a9ffb71

File tree

7 files changed

+1533
-720
lines changed

7 files changed

+1533
-720
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
395395
ISD::FADD, ISD::FSUB,
396396
ISD::FMUL, ISD::FMA,
397397
ISD::FDIV, ISD::FSQRT,
398-
ISD::FABS, ISD::FNEG,
399398
ISD::STRICT_FMA, ISD::STRICT_FADD,
400399
ISD::STRICT_FSUB, ISD::STRICT_FMUL,
401400
ISD::STRICT_FDIV, ISD::STRICT_FSQRT,
@@ -416,8 +415,8 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
416415
setOperationAction(ISD::BR_CC, MVT::bf16, Expand);
417416
setOperationAction(ZfhminZfbfminPromoteOps, MVT::bf16, Promote);
418417
setOperationAction(ISD::FREM, MVT::bf16, Promote);
419-
// FIXME: Need to promote bf16 FCOPYSIGN to f32, but the
420-
// DAGCombiner::visitFP_ROUND probably needs improvements first.
418+
setOperationAction(ISD::FABS, MVT::bf16, Expand);
419+
setOperationAction(ISD::FNEG, MVT::bf16, Expand);
421420
setOperationAction(ISD::FCOPYSIGN, MVT::bf16, Expand);
422421
}
423422

@@ -433,8 +432,8 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
433432
setOperationAction({ISD::STRICT_LRINT, ISD::STRICT_LLRINT,
434433
ISD::STRICT_LROUND, ISD::STRICT_LLROUND},
435434
MVT::f16, Legal);
436-
// FIXME: Need to promote f16 FCOPYSIGN to f32, but the
437-
// DAGCombiner::visitFP_ROUND probably needs improvements first.
435+
setOperationAction(ISD::FABS, MVT::f16, Expand);
436+
setOperationAction(ISD::FNEG, MVT::f16, Expand);
438437
setOperationAction(ISD::FCOPYSIGN, MVT::f16, Expand);
439438
}
440439

0 commit comments

Comments
 (0)