Skip to content

Commit 1e3a036

Browse files
committed
[RISCV]: Use FMUL instead of fminimum_num
1 parent 08b567c commit 1e3a036

File tree

2 files changed

+237
-2139
lines changed

2 files changed

+237
-2139
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,22 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FABS(SDNode *N) {
315315

316316
SDValue DAGTypeLegalizer::SoftenFloatRes_FCANONICALIZE(SDNode *N) {
317317
SDLoc dl(N);
318-
SDValue Node = DAG.getNode(ISD::FMINIMUMNUM, dl, N->getValueType(0),
319-
N->getOperand(0), N->getOperand(0));
318+
319+
// Create a constant 1.0, then soften it to integer and record the mapping.
320+
SDValue CstFP = DAG.getConstantFP(1.0, dl, N->getValueType(0));
321+
SDValue CstInt = SoftenFloatRes_ConstantFP(CstFP.getNode());
322+
323+
if (!SoftenedFloats[getTableId(CstFP)])
324+
SetSoftenedFloat(CstFP, CstInt);
325+
326+
// Multiply the input by 1.0 to canonicalize it. We use `MorphNodeTo` to
327+
// avoid constant folding, which happens with `DAG.getNode(ISD::FMUL, ...)`.
328+
SDNode *Node =
329+
DAG.MorphNodeTo(N, ISD::FMUL, DAG.getVTList(N->getValueType(0)),
330+
{N->getOperand(0), CstFP});
320331
return SoftenFloatRes_Binary(
321-
Node.getNode(),
322-
GetFPLibCall(N->getValueType(0), RTLIB::FMINIMUM_NUM_F32,
323-
RTLIB::FMINIMUM_NUM_F64, RTLIB::FMINIMUM_NUM_F80,
324-
RTLIB::FMINIMUM_NUM_F128, RTLIB::FMINIMUM_NUM_PPCF128));
332+
Node, GetFPLibCall(N->getValueType(0), RTLIB::MUL_F32, RTLIB::MUL_F64,
333+
RTLIB::MUL_F80, RTLIB::MUL_F128, RTLIB::MUL_PPCF128));
325334
}
326335

327336
SDValue DAGTypeLegalizer::SoftenFloatRes_FMINNUM(SDNode *N) {

0 commit comments

Comments
 (0)