[PATCH] D110579: [AMDGPU] Add two new intrinsics to control fp_trunc rounding mode

Serge Pavlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 2 19:02:31 PST 2021


sepavloff added inline comments.


================
Comment at: llvm/include/llvm/IR/Intrinsics.td:914
+// Trunc a floating point number with a -inf rounding
+def int_experimental_fptrunc_round_downward : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
+                                                    [ llvm_anyfloat_ty ]>;
----------------
jpages wrote:
> sepavloff wrote:
> > sepavloff wrote:
> > > What is the difference between this function and `llvm.floor`?
> > > 
> > > There are also functions `llvm.nearbyint` and `llvm.rint` that can be used to make rounding with any mode.
> > Oh, I see, this is conversion between floats.
> > 
> > There is `llvm.experimental.constrained.fptrunc`, which seems to do the same thing?
> Yes, this is indeed a conversion between floats.
> 
> The idea of this change is to introduce something simpler than constrained intrinsics in a special case.
> 
> According to https://llvm.org/docs/LangRef.html#constrained-floating-point-intrinsics "If any FP operation in a function is constrained then they all must be constrained".
> 
> We wanted to do a simpler conversion from f32 -> f16 with a special rounding mode, but without constraining the rest of the function after this operation. Introducing an Intrinsic that would be lowered to 3 instructions seemed to be the best solution.
> 
> These 3 instructions are:
> - Setting a special rounding mode
> - Conversion f32 -> f16
> - Restoring the rounding mode to the default value
> 
> 
> 
This would be a useful function, which solves a widespread task. On some platforms, like RISC-V, it even can be lowered into a single instruction.

As this is common interface, I would propose you to make rounding mode an argument. It would allows a target to implement the conversion with any supported mode. Besides, it would allow future extensions without changing the interface, for example, to allow other control modes:

    lvm.fptrunc.round(%a, !"round.towardzero,denorm.ftz")

What prevents from making it a regular intrinsic, not experimental?



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110579/new/

https://reviews.llvm.org/D110579



More information about the llvm-commits mailing list