[llvm] [SelectionDAG][RISCV] Operations with static rounding (PR #100999)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 29 05:12:35 PDT 2024
================
@@ -8131,15 +8131,73 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
void SelectionDAGBuilder::visitConstrainedFPIntrinsic(
const ConstrainedFPIntrinsic &FPI) {
SDLoc sdl = getCurSDLoc();
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
+ EVT VT = TLI.getValueType(DAG.getDataLayout(), FPI.getType());
+ fp::ExceptionBehavior EB = *FPI.getExceptionBehavior();
+ std::optional<RoundingMode> RM = FPI.getRoundingMode();
+
+ SDNodeFlags Flags;
+ if (EB == fp::ExceptionBehavior::ebIgnore)
+ Flags.setNoFPExcept(true);
+
+ if (auto *FPOp = dyn_cast<FPMathOperator>(&FPI))
+ Flags.copyFMF(*FPOp);
+
+ bool UseStaticRounding = EB == fp::ExceptionBehavior::ebIgnore && RM &&
+ *RM != RoundingMode::Dynamic &&
+ TLI.isStaticRoundingSupportedFor(FPI);
+ unsigned Opcode = 0;
+ SmallVector<SDValue, 4> Opers;
+ for (unsigned I = 0, E = FPI.getNonMetadataArgCount(); I != E; ++I)
+ Opers.push_back(getValue(FPI.getArgOperand(I)));
+
+ if (UseStaticRounding) {
+ switch (FPI.getIntrinsicID()) {
+ case Intrinsic::experimental_constrained_fadd:
+ Opcode = ISD::FADD_MODE;
+ break;
+ case Intrinsic::experimental_constrained_fsub:
+ Opcode = ISD::FSUB_MODE;
+ break;
+ case Intrinsic::experimental_constrained_fmul:
+ Opcode = ISD::FMUL_MODE;
+ break;
+ case Intrinsic::experimental_constrained_fdiv:
+ Opcode = ISD::FDIV_MODE;
+ break;
+ case Intrinsic::experimental_constrained_sqrt:
+ Opcode = ISD::FSQRT_MODE;
+ break;
+ case Intrinsic::experimental_constrained_fma:
+ Opcode = ISD::FMA_MODE;
+ break;
+ case Intrinsic::experimental_constrained_sitofp:
+ Opcode = ISD::SINT_TO_FP_MODE;
+ break;
+ case Intrinsic::experimental_constrained_uitofp:
+ Opcode = ISD::UINT_TO_FP_MODE;
+ break;
+ case Intrinsic::experimental_constrained_fptrunc:
+ Opcode = ISD::FP_ROUND_MODE;
+ break;
+ }
+ if (Opcode) {
+ int MachineRM = TLI.getMachineRoundingMode(*RM);
+ assert(MachineRM >= 0 && "Unsupported rounding mode");
+ EVT RMType = TLI.getTypeToTransformTo(*DAG.getContext(), MVT::i32);
+ Opers.push_back(DAG.getConstant(static_cast<uint64_t>(MachineRM), sdl,
----------------
arsenm wrote:
getTargetConstant
https://github.com/llvm/llvm-project/pull/100999
More information about the llvm-commits
mailing list