[PATCH] [X86] Updates to X86 backend for f16 promotion

Ahmed Bougacha ahmed.bougacha at gmail.com
Thu Apr 30 13:37:54 PDT 2015


================
Comment at: test/CodeGen/X86/half.ll:157
@@ +156,3 @@
+; CHECK: callq  __truncdfhf2
+  %v = fptrunc <4 x double> %a to <4 x half>
+  store <4 x half> %v, <4 x half>* %p
----------------
pirama wrote:
> delena wrote:
> > Why double to half can't go through the chain (double -> float ->half). I'm just asking..
> A chained conversion through float is done if unsafe math is enabled (See around line 3458 in lib/CodeGen/SelectionDAG/LegalizeDAG.cpp).  Interestingly, half -> double goes through an intermediate float (this is done in the 'case ISD::FP16_TO_FP' just above.
> 
> I am not sure why double -> float -> half is considered a precision loss, while the reverse chain isn't.
The problem is double rounding:  the first round can expose a tie to be broken by the second round, which wouldn't happen with single-step rounding.
For instance, consider "1.49" with round-to-even.  Rounded directly to 1 digit gets you 1.  Rounding first to 2 digits gets you 1.5, and if you round that again to 1 digit, you get 2, a different result.

The reverse is fine, since you're basically adding trailing zero bits to the mantissa.  For 1.49, that would be akin to turning 1.49 into 1.49000.  You can first do 1.490, then 1.49000: the result is the same.

http://reviews.llvm.org/D9092

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list