[PATCH] D69275: Add constrained int->FP intrinsics

Ulrich Weigand via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 27 07:04:14 PST 2019


uweigand added inline comments.


================
Comment at: llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp:2653
+    return Res;
+  }
+
----------------
craig.topper wrote:
> uweigand wrote:
> > This confuses me again.   It seems this may generate a SINT_TO_FP -> HalfVT -> FP_ROUND -> OutVT chain, which introduces a potential double rounding that can lead to incorrect results even disregarding any constrained FP semantics ...
> For the only case we have tests for i64->f16. I think any integer value large enough to cause rounding when converted to f32 would be too large to represent at all in f16. Since f16's max exponent of 15 is less than the length of f32's mantissa.
Ah yes, you're right. So this should be fine with non-strict semantics.  

And for strict semantics, we should also be fine.  The int->f32 conversion can only raise an inexact exception, and this only in cases where the int->f16 conversion **should** raise an inexact.  The f32->f16 conversion due to construction of the input also can only raise an inexact exception, and again only in cases where we should have one.  Conversely, in every case where we should have an inexact exception, one (or both) of the intermediate steps will raise it.   (I think there may be cases where we get two, but that should be fine even for strict semantics.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69275





More information about the llvm-commits mailing list