<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 17, 2016, at 4:33 PM, Hal Finkel <<a href="mailto:hfinkel@anl.gov" class="">hfinkel@anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><hr id="zwchr" style="font-family: arial, helvetica, sans-serif; font-size: 13.333333015441895px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class=""><b class="">From:<span class="Apple-converted-space"> </span></b>"Warren Ristow" <<a href="mailto:warren.ristow@sony.com" class="">warren.ristow@sony.com</a>><br class=""><b class="">To:<span class="Apple-converted-space"> </span></b>"Sanjay Patel" <<a href="mailto:spatel@rotateright.com" class="">spatel@rotateright.com</a>>, "cfe-dev" <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>>, "llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>><br class=""><b class="">Cc:<span class="Apple-converted-space"> </span></b>"Nicolai Hähnle" <<a href="mailto:nhaehnle@gmail.com" class="">nhaehnle@gmail.com</a>>, "Hal Finkel" <<a href="mailto:hfinkel@anl.gov" class="">hfinkel@anl.gov</a>>, "Mehdi Amini" <<a href="mailto:mehdi.amini@apple.com" class="">mehdi.amini@apple.com</a>>, "andrew kaylor" <<a href="mailto:andrew.kaylor@intel.com" class="">andrew.kaylor@intel.com</a>><br class=""><b class="">Sent:<span class="Apple-converted-space"> </span></b>Thursday, November 17, 2016 5:58:58 PM<br class=""><b class="">Subject:<span class="Apple-converted-space"> </span></b>RE: what does -ffp-contract=fast allow?<br class=""><br class=""><div class="WordSection1" style="page: WordSection1;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class="">> Is this a bug? We transformed the original expression into:<br class="">> x * y + x<br class=""><br class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class=""></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class="">I’d say yes, it’s a bug.</span></div><p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class=""> </span></p><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span id="DWT2241" style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class="">Unless ‑ffast‑math is used (or some appropriate subset that gives us leeway, like ‑fno‑honor‑infinities or ‑fno‑honor‑nans, or somesuch), the re-association isn’t allowed, and that blocks the madd contraction.</span></div></div></blockquote><span style="font-family: arial, helvetica, sans-serif; font-size: 13.333333015441895px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I agree. FP contraction alone only allows us to do x*y+z -> fma(x,y,z).</span><br style="font-family: arial, helvetica, sans-serif; font-size: 13.333333015441895px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>I agree too, but the more difficult question is "which flags are needed here?”</div><div>Would FPContract + no-inf be enough? If not why and how to document it?</div><div><br class=""></div><div><br class=""></div><div>— </div><div>Mehdi</div><div><br class=""></div><div><br class=""></div><blockquote type="cite" class=""><div class=""><blockquote style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class=""><div class="WordSection1" style="page: WordSection1;"><p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"></p></div></blockquote></div></blockquote><br class=""><blockquote type="cite" class=""><div class=""><blockquote style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt;" class=""><div class="WordSection1" style="page: WordSection1;"><p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class=""> </span></p><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><b class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif;" class="">From:</span></b><span style="font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span class="Apple-converted-space"> </span>Sanjay Patel [<a href="mailto:spatel@rotateright.com" class="">mailto:spatel@rotateright.com</a>]<span class="Apple-converted-space"> </span><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Thursday, November 17, 2016 3:22 PM<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>>; llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>Nicolai Hähnle <<a href="mailto:nhaehnle@gmail.com" class="">nhaehnle@gmail.com</a>>; Hal Finkel <<a href="mailto:hfinkel@anl.gov" class="">hfinkel@anl.gov</a>>; Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" class="">mehdi.amini@apple.com</a>>; Ristow, Warren <<a href="mailto:warren.ristow@sony.com" class="">warren.ristow@sony.com</a>>; <a href="mailto:andrew.kaylor@intel.com" class="">andrew.kaylor@intel.com</a><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>what does -ffp-contract=fast allow?</span></div><p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> </p><div class=""><p class="MsoNormal" style="margin: 0in 0in 12pt; font-size: 12pt; font-family: 'Times New Roman', serif;">This is just paraphrasing from D26602, so credit to Nicolai for first raising the issue there.<br class=""><br class="">float foo(float x, float y) {<br class=""> return x * (y + 1);<br class="">}<br class=""><br class="">$ ./clang -O2 xy1.c -S -o - -target aarch64 -ffp-contract=fast | grep fm<br class=""> fmadd s0, s1, s0, s0<br class=""><br class="">Is this a bug? We transformed the original expression into:<br class="">x * y + x<br class=""><br class="">When x=INF and y=0, the code returns INF if we don't reassociate. With reassociation to FMA, it returns NAN because 0 * INF = NAN.<br class=""><br class="">1. I used aarch64 as the example target, but this is not target-dependent (as long as the target has FMA).<br class=""><br class="">2. This is *not* -ffast-math...or is it? The C standard only shows on/off settings for the associated FP_CONTRACT pragma.<br class=""><br class="">3. AFAIK, clang has no documentation for -ffp-contract:<br class=""><a href="http://clang.llvm.org/docs/UsersManual.html" target="_blank" style="color: purple; text-decoration: underline;" class="">http://clang.llvm.org/docs/UsersManual.html</a><br class=""><br class="">4. GCC says:<br class=""><a href="https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gcc/Optimize-Options.html#Optimize-Options" target="_blank" style="color: purple; text-decoration: underline;" class="">https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gcc/Optimize-Options.html#Optimize-Options</a><br class="">"-ffp-contract=fast enables floating-point expression contraction such as forming of fused multiply-add operations if the target has native support for them."<br class=""><br class="">5. The LLVM backend (where this reassociation currently happens) shows:<br class="">FPOpFusion::Fast - Enable fusion of FP ops wherever it's profitable.</p></div></div></blockquote><br style="font-family: arial, helvetica, sans-serif; font-size: 13.333333015441895px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: arial, helvetica, sans-serif; font-size: 13.333333015441895px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: arial, helvetica, sans-serif; font-size: 13.333333015441895px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: arial, helvetica, sans-serif; font-size: 13.333333015441895px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">--<span class="Apple-converted-space"> </span></span><br style="font-family: arial, helvetica, sans-serif; font-size: 13.333333015441895px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div style="font-family: arial, helvetica, sans-serif; font-size: 13.333333015441895px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span name="x" class=""></span>Hal Finkel<br class="">Lead, Compiler Technology and Programming Languages<br class="">Leadership Computing Facility<br class="">Argonne National Laboratory</div></div></blockquote></div><br class=""></body></html>