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

Julien Pagès via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 2 09:35:34 PST 2021


jpages 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 ]>;
----------------
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





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