<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Oct 30, 2012, at 8:23 AM, Dan Gohman <<a href="mailto:dan433584@gmail.com">dan433584@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi Micheal,<br><br>On Mon, Oct 29, 2012 at 4:34 PM, Michael Ilseman <span dir="ltr"><<a href="mailto:milseman@apple.com" target="_blank">milseman@apple.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">
I<br>
Flags<br>
---<br>
no NaNs (N)<br>
  - ignore the existence of NaNs when convenient<br>
no Infs (I)<br>
  - ignore the existence of Infs when convenient<br>
no signed zeros (S)<br>
  - ignore the existence of negative zero when convenient<br></blockquote><div><br>Does this mean ignore the possibility of NaNs as operands, as results, or both? Ditto for infinity and negative zero.<br><br></div></div></blockquote><div><br></div><div>I wrote this thinking both, though I could certainly imagine it being clearer if defined as operands. The example optimizations section is written along the lines of ignoring both.</div><br><blockquote type="cite"><div class="gmail_quote"><div>Also, what does "ignore" mean? As worded, it seems to imply Undefined Behavior if the value is encountered. Is that intended?<br>
 </div></div></blockquote><div><br></div><div>What I'm intending is for optimizations to be allowed to ignore the possibility of those values. Thinking about it more, this is pretty vague. With your and Krzysztof's feedback in mind, I think something along the lines of:</div><div><br></div><div>no NaNs (N)</div><div>  - The operands' values can be assumed to be non-NaN by the optimizer. The result of this operator is Undef if passed a NaN.</div><div><br></div><div>Might be more clear. I'll think about that more and revise the examples section too.</div><br><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
allow fusion (F)<br>
  - fuse FP operations when convenient, despite possible differences in rounding<br>
    (e.g. form FMAs)<br></blockquote><div><br>What do you intend to be the relationship between this and @llvm.fmuladd? It's not clear whether you're trying to replace it or trying to set up an alternative for different use cases.<br>
<br></div></div></blockquote><div><br></div><div>Interesting, I had not seen llvm.fmuladd. I'll have to think about this more; perhaps fmuladd can already provide what I was intending here.</div><br><blockquote type="cite"><div class="gmail_quote"><div>Is your wording of "fusing" intended to imply fusing with infinite intermediate precision only, or is mere increased precision also valid?<br><br></div></div></blockquote><div><br></div><div>My intention is that increased precision is also valid, though I haven't though too deeply about the difference</div><br><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; position: static; z-index: auto; ">

unsafe algebra (A)<br>
  - allow for algebraically equivalent transformations that may dramatically<br>
    change results in floating point. (e.g. reassociation)<br></blockquote><div>[...] <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; position: static; z-index: auto; ">
Not all combinations make sense (e.g. 'A' pretty much implies all other flags).<br>
<br>
Basically, I have the below semilattice of sensible relations:<br>
  A > S > I > N<br>
  A > F<br>
Meaning that 'A' implies all the others, 'S' implies 'I' and 'N', etc.<br></blockquote><div><br>Why does it make sense for S to imply I and N? GCC's -fno-signed-zeros flag doesn't seem to imply -ffinite-math-only, among other things. The concept of negative zero isn't inherently linked with the concepts of infinity or NaN.<br>
 <br></div></div></blockquote><div><br></div><div>What I mean here is that I'm finding it hard to think of a case where a user would desire to specify 'I' and not specify 'N'. This is more so a question I had as to whether we could/should express this as a fast-math level rather than allow each flag to be individually toggle-able. Any thoughts on this?</div><br><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
It might make sense to change the S, I, and N options to be some kind of finite<br>
option with levels 3, 2, and 1 respectively. F and A could be kept distinct. It<br>
is still the case that A would imply pretty much everything else.<br>
<br>
N - no NaNs<br>
  x == x ==> true<br></blockquote><div><br>This is not true if x is infinity.<br> <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
S - no signed zeros<br>
  x - 0 ==> x<br>
  0 - (x - y) ==> y - x<br>
<br>
NS - no signed zeros AND no NaNs<br>
  x * 0 ==> 0<br>
<br>
NI - no infs AND no NaNs<br>
  x - x ==> 0<br>
  Inf > x ==> true<br></blockquote><div><br>With the I flag, would the infinity as an operand make this undefined?<br> </div></div></blockquote><div><br></div><div>I'll think about this more with regards to the prior changes.</div><br><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

<br>
A - unsafe-algebra<br>
  Reassociation<br>
    (x + C1) + C2 ==> x + (C1 + C2)<br></blockquote><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  Redistribution<br>
    (x * C) + x ==> x * (C+1)<br>
    (x * C) + (x + x) ==> x * (C + 2)<br>
  Reciprocal<br>
   x / C ==> x * (1/C)<br>
<br>
These examples apply when the new constants are permitted, e.g. not denormal,<br>
and all the instructions involved have the needed flags.<br></blockquote><div><br>I'm confused. In other places, you seem to apply that reassociation would be valid even on non-constant values. It's not clear whether you meant to contradict that here.<br>
 
<br></div></div></blockquote><div><br></div><div>Reassociation is still valid. These examples are just cases where there would be a clear optimization benefit to be had. I'll probably add in a general expression to clarify.</div><div><br></div><br><blockquote type="cite"><div class="gmail_quote"><div>[...]<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; position: static; z-index: auto; ">
-fp-contract=<value><br>
  I'm not too familiar with this option, but I recommend that 'all' turn on the<br>
  'F' bit for all FP instructinos, default do so when following the pragma, and<br>
  off never doing so. This option should still be passed to the backend.<br></blockquote><div><br>Please coordinate with Lang and others who have already done a fair amount of work on FP_CONTRACT.<br></div></div></blockquote><div><br></div><div>I will, thanks.</div><br><blockquote type="cite"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; position: static; z-index: auto; ">

<br>
(Optional)<br>
I propose adding the below flags:<br>
<br>
-ffinite-math-only<br>
  Allow optimizations to assume that floating point arguments and results are<br>
  NaNs or +/-Inf. This may produce incorrect results, and so should be used with<br>
  care.<br>
<br>
  This would set the 'I' and 'N' bits on all generated floating point instructions.<br>
<br>
-fno-signed-zeros<br>
  Allow optimizations to ignore the signedness of zero. This may produce<br>
  incorrect results, and so should be used with care.<br>
<br>
  This would set the 'S' bit on all FP instructions.<br></blockquote><div><br>These are established flags in GCC. Do you know if there are any semantic differences between your proposed semantics and the semantics of these flags in GCC? If so, it would be good to either change to match them, or document the differences.<br>
<br></div></div></blockquote><div><br></div><div>I don't know of any differences, but I'll have to look into GCC's behavior more.</div><br><blockquote type="cite"><div class="gmail_quote"><div>Dan<br><br></div></div>
</blockquote></div><br><div>Thanks for the feedback!</div></body></html>