@@ -35,7 +35,8 @@ static LegalityPredicate typeIsScalarFPArith(unsigned TypeIdx,
3535 const RISCVSubtarget &ST ) {
3636 return [=, &ST ](const LegalityQuery &Query) {
3737 return Query.Types [TypeIdx].isScalar () &&
38- ((ST .hasStdExtF () && Query.Types [TypeIdx].getSizeInBits () == 32 ) ||
38+ ((ST .hasStdExtZfh () && Query.Types [TypeIdx].getSizeInBits () == 16 ) ||
39+ (ST .hasStdExtF () && Query.Types [TypeIdx].getSizeInBits () == 32 ) ||
3940 (ST .hasStdExtD () && Query.Types [TypeIdx].getSizeInBits () == 64 ));
4041 };
4142}
@@ -371,25 +372,17 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
371372
372373 // FP Operations
373374
374- auto &FPArithActions = getActionDefinitionsBuilder (
375- {G_FADD , G_FSUB , G_FMUL , G_FDIV , G_FMA , G_FNEG ,
376- G_FABS , G_FSQRT , G_FMAXNUM , G_FMINNUM })
377- .legalIf (typeIsScalarFPArith (0 , ST ));
378- // TODO: Fold this into typeIsScalarFPArith.
379- if (ST .hasStdExtZfh ())
380- FPArithActions.legalFor ({s16});
375+ getActionDefinitionsBuilder ({G_FADD , G_FSUB , G_FMUL , G_FDIV , G_FMA , G_FNEG ,
376+ G_FABS , G_FSQRT , G_FMAXNUM , G_FMINNUM })
377+ .legalIf (typeIsScalarFPArith (0 , ST ));
381378
382379 getActionDefinitionsBuilder (G_FREM )
383380 .libcallFor ({s32, s64})
384381 .minScalar (0 , s32)
385382 .scalarize (0 );
386383
387- auto &CopySignActions =
388- getActionDefinitionsBuilder (G_FCOPYSIGN )
389- .legalIf (all (typeIsScalarFPArith (0 , ST ), typeIsScalarFPArith (1 , ST )));
390- // TODO: Fold this into typeIsScalarFPArith.
391- if (ST .hasStdExtZfh ())
392- CopySignActions.legalFor ({s16, s16});
384+ getActionDefinitionsBuilder (G_FCOPYSIGN )
385+ .legalIf (all (typeIsScalarFPArith (0 , ST ), typeIsScalarFPArith (1 , ST )));
393386
394387 getActionDefinitionsBuilder (G_FPTRUNC ).legalIf (
395388 [=, &ST ](const LegalityQuery &Query) -> bool {
@@ -402,40 +395,28 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
402395 typeIs (1 , s32)(Query));
403396 });
404397
405- auto &FCmpActions = getActionDefinitionsBuilder (G_FCMP ).legalIf (
406- all (typeIs (0 , sXLen ), typeIsScalarFPArith (1 , ST )));
407- // TODO: Fold this into typeIsScalarFPArith.
408- if (ST .hasStdExtZfh ())
409- FCmpActions.legalFor ({sXLen , s16});
410- FCmpActions.clampScalar (0 , sXLen , sXLen );
398+ getActionDefinitionsBuilder (G_FCMP )
399+ .legalIf (all (typeIs (0 , sXLen ), typeIsScalarFPArith (1 , ST )))
400+ .clampScalar (0 , sXLen , sXLen );
411401
412402 // TODO: Support vector version of G_IS_FPCLASS.
413- auto &FClassActions =
414- getActionDefinitionsBuilder (G_IS_FPCLASS )
415- .customIf (all (typeIs (0 , s1), typeIsScalarFPArith (1 , ST )));
416- // TODO: Fold this into typeIsScalarFPArith.
417- if (ST .hasStdExtZfh ())
418- FClassActions.customFor ({s1, s16});
419-
420- auto &FConstantActions = getActionDefinitionsBuilder (G_FCONSTANT )
421- .legalIf (typeIsScalarFPArith (0 , ST ));
422- if (ST .hasStdExtZfh ())
423- FConstantActions.legalFor ({s16});
424- FConstantActions.lowerFor ({s32, s64});
425-
426- auto &FPToIActions =
427- getActionDefinitionsBuilder ({G_FPTOSI , G_FPTOUI })
428- .legalIf (all (typeInSet (0 , {s32, sXLen }), typeIsScalarFPArith (1 , ST )));
429- if (ST .hasStdExtZfh ())
430- FPToIActions.legalFor ({{s32, s16}, {sXLen , s16}});
431- FPToIActions.widenScalarToNextPow2 (0 ).clampScalar (0 , s32, sXLen ).libcall ();
432-
433- auto &IToFPActions =
434- getActionDefinitionsBuilder ({G_SITOFP , G_UITOFP })
435- .legalIf (all (typeIsScalarFPArith (0 , ST ), typeInSet (1 , {s32, sXLen })));
436- if (ST .hasStdExtZfh ())
437- IToFPActions.legalFor ({{s16, s32}, {s16, sXLen }});
438- IToFPActions.widenScalarToNextPow2 (1 ).clampScalar (1 , s32, sXLen );
403+ getActionDefinitionsBuilder (G_IS_FPCLASS )
404+ .customIf (all (typeIs (0 , s1), typeIsScalarFPArith (1 , ST )));
405+
406+ getActionDefinitionsBuilder (G_FCONSTANT )
407+ .legalIf (typeIsScalarFPArith (0 , ST ))
408+ .lowerFor ({s32, s64});
409+
410+ getActionDefinitionsBuilder ({G_FPTOSI , G_FPTOUI })
411+ .legalIf (all (typeInSet (0 , {s32, sXLen }), typeIsScalarFPArith (1 , ST )))
412+ .widenScalarToNextPow2 (0 )
413+ .clampScalar (0 , s32, sXLen )
414+ .libcall ();
415+
416+ getActionDefinitionsBuilder ({G_SITOFP , G_UITOFP })
417+ .legalIf (all (typeIsScalarFPArith (0 , ST ), typeInSet (1 , {s32, sXLen })))
418+ .widenScalarToNextPow2 (1 )
419+ .clampScalar (1 , s32, sXLen );
439420
440421 // FIXME: We can do custom inline expansion like SelectionDAG.
441422 // FIXME: Legal with Zfa.
0 commit comments