<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 Jan 9, 2018, at 1:53 PM, Kaylor, Andrew via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><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 think we’re going to need to create a new mechanism to communicate strict FP modes to the backend. I think we need to avoid doing anything that will require re-inventing or duplicating all of the pattern matching that goes on in instruction selection (which is the reason we’re currently dropping that information). I’m out of my depth on this transition, but I think maybe we could handle it with some kind of attribute on the MBB.<o:p class=""></o:p></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=""><o:p class=""> </o:p></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="">In C/C++, at least, it’s my understanding that the pragmas always apply at the scope-level (as opposed to having the possibility of being instruction-specific), and we’ve previously agreed that our implementation will really need to apply the rules across entire functions in the sense that if any part of a function uses the constrained intrinsics all FP operations in the function will need to use them (though different metadata arguments may be used in different scopes). So I think that opens our options a bit.<o:p class=""></o:p></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=""><o:p class=""> </o:p></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="">Regarding constant folding, I think you are correct that it isn’t happening anywhere in the backends at the moment. There is some constant folding done during instruction selection, but the existing mechanism prevents that. My concern is that given LLVM’s development model, if there is nothing in place to prevent constant folding and no consensus that it shouldn’t be allowed then we should probably believe that someone will eventually do it.</span></div></div></div></blockquote><div><br class=""></div>The standard argument against trying to introduce "scope-like" mechanisms to LLVM IR is inlining; unless you're going to prevent functions that use stricter/laxer FP rules from being inlined into each other (which sounds disastrous), you're going to need to communicate strictness on an instruction-by-instruction basis.  If the backend wants to handle that by using the strictest rule that it sees in use anywhere in the function because pattern-matching is otherwise too error-prone, ok, that's its right; but the IR really should be per-instruction.</div><div><br class=""></div><div>John.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class="WordSection1" style="page: WordSection1; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><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=""><o:p class=""></o:p></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=""><o:p class=""> </o:p></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="">-Andy<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><a name="_MailEndCompose" class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class=""><o:p class=""> </o:p></span></a></div><div class=""><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0in 0in;" class=""><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>Ulrich Weigand [<a href="mailto:Ulrich.Weigand@de.ibm.com" style="color: rgb(149, 79, 114); text-decoration: underline;" class="">mailto:Ulrich.Weigand@de.ibm.com</a>]<span class="Apple-converted-space"> </span><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Tuesday, January 09, 2018 9:59 AM<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Kaylor, Andrew <<a href="mailto:andrew.kaylor@intel.com" style="color: rgb(149, 79, 114); text-decoration: underline;" class="">andrew.kaylor@intel.com</a>>;<span class="Apple-converted-space"> </span><a href="mailto:kpn@neutralgood.org" style="color: rgb(149, 79, 114); text-decoration: underline;" class="">kpn@neutralgood.org</a><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>Hal Finkel <<a href="mailto:hfinkel@anl.gov" style="color: rgb(149, 79, 114); text-decoration: underline;" class="">hfinkel@anl.gov</a>>; Richard Smith <<a href="mailto:richard@metafoo.co.uk" style="color: rgb(149, 79, 114); text-decoration: underline;" class="">richard@metafoo.co.uk</a>>;<span class="Apple-converted-space"> </span><a href="mailto:bob.huemmer@sas.com" style="color: rgb(149, 79, 114); text-decoration: underline;" class="">bob.huemmer@sas.com</a>;<span class="Apple-converted-space"> </span><a href="mailto:bumblebritches57@gmail.com" style="color: rgb(149, 79, 114); text-decoration: underline;" class="">bumblebritches57@gmail.com</a>;<span class="Apple-converted-space"> </span><a href="mailto:wei.ding2@amd.com" style="color: rgb(149, 79, 114); text-decoration: underline;" class="">wei.ding2@amd.com</a>;<span class="Apple-converted-space"> </span><a href="mailto:cfe-dev@lists.llvm.org" style="color: rgb(149, 79, 114); text-decoration: underline;" class="">cfe-dev@lists.llvm.org</a>; llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" style="color: rgb(149, 79, 114); text-decoration: underline;" class="">llvm-dev@lists.llvm.org</a>><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>Re: [cfe-dev] Why is #pragma STDC FENV_ACCESS not supported?<o:p class=""></o:p></span></div></div></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div><p style="margin-right: 0in; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 10pt;" class="">Andrew Kaylor wrote:</span><br class=""><br class=""><tt style="font-family: 'Courier New';" class=""><span style="font-size: 10pt;" class="">>In general, the current "strict FP" handling stops at instruction</span></tt><br class=""><tt style="font-family: 'Courier New';" class=""><span style="font-size: 10pt;" class="">>selection. At the MachineIR level we don't currently have a mechanism</span></tt><br class=""><tt style="font-family: 'Courier New';" class=""><span style="font-size: 10pt;" class="">>to prevent inappropriate optimizations based on floating point</span></tt><br class=""><tt style="font-family: 'Courier New';" class=""><span style="font-size: 10pt;" class="">>constraints, or indeed to convey such constraints to the backend.</span></tt><br class=""><tt style="font-family: 'Courier New';" class=""><span style="font-size: 10pt;" class="">>Implicit register use modeling may provide some restriction on some</span></tt><br class=""><tt style="font-family: 'Courier New';" class=""><span style="font-size: 10pt;" class="">>architectures, but this is definitely lacking for X86 targets. On the</span></tt><br class=""><tt style="font-family: 'Courier New';" class=""><span style="font-size: 10pt;" class="">>other hand, I'm not aware of any specific current problems, so in many</span></tt><br class=""><tt style="font-family: 'Courier New';" class=""><span style="font-size: 10pt;" class="">>cases we may "get lucky" and have the correct thing happen by chance.</span></tt><br class=""><tt style="font-family: 'Courier New';" class=""><span style="font-size: 10pt;" class="">>Obviously that's not a viable long term solution. I have a rough plan</span></tt><br class=""><tt style="font-family: 'Courier New';" class=""><span style="font-size: 10pt;" class="">>for adding improved register modeling to the X86 backend, which should</span></tt><br class=""><tt style="font-family: 'Courier New';" class=""><span style="font-size: 10pt;" class="">>take care of instruction scheduling issues, but we'd still need a</span></tt><br class=""><tt style="font-family: 'Courier New';" class=""><span style="font-size: 10pt;" class="">>mechanism to prevent constant folding optimizations and such.</span></tt><br class=""><span style="font-size: 10pt;" class=""><br class="">Given that Kevin intends to target SystemZ, I'll be happy to work on the SystemZ back-end support for this feature. I agree that we should be using implicit control register dependencies, which will at least prevent moving floating-point operations across instructions that e.g. change rounding modes. However, the main property we need to model is that floating-point operations may *trap*. I guess this can be done using UnmodeledSideEffects, but I'm not quite clear on how to make this dependent on whether or not a "strict" operation is requested (without duplicating all the instruction patterns ...).</span><br class=""><br class=""><span style="font-size: 10pt;" class="">Once we do use something like UnmodeledSideEffects, I think MachineIR passes should handle everything correctly; in the end, the requirements are not really different from those of other trapping instructions. B.t.w. I don't think anybody does constant folding on floating-point constants at the MachineIR level anyway ... have you seen this anywhere?</span><br class=""><br class=""><span style="font-size: 10pt;" class=""><br class="">Mit freundlichen Gruessen / Best Regards<br class=""><br class="">Ulrich Weigand<br class=""><br class="">--<span class="Apple-converted-space"> </span><br class="">Dr. Ulrich Weigand | Phone: +49-7031/16-3727<br class="">STSM, GNU/Linux compilers and toolchain<br class="">IBM Deutschland Research & Development GmbH<br class="">Vorsitzende des Aufsichtsrats: Martina Koederitz | Geschäftsführung: Dirk Wittkopp<br class="">Sitz der Gesellschaft: Böblingen | Registergericht: Amtsgericht Stuttgart, HRB 243294</span><o:p class=""></o:p></p></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">cfe-dev mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:cfe-dev@lists.llvm.org" style="color: rgb(149, 79, 114); text-decoration: underline; font-family: Helvetica; font-size: 12px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">cfe-dev@lists.llvm.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" style="color: rgb(149, 79, 114); text-decoration: underline; font-family: Helvetica; font-size: 12px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote></div><br class=""></body></html>