<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div data-marker="__QUOTED_TEXT__"><div><div style="font-family: "arial", "helvetica", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><div>Hello,<br><br>In our Kalray LLVM backend, we have builtins to get and set system registers. One of them is $CS, which has sticky bits enforcing rounding mode or storing masked floating-point exceptions. The equivalent on AArch64 would be FPCR.<br><br>In our user code, we would like to preserve the partial ordering between a SET to $CS and a floating-point operation, since the SET to $CS might be modifying the rounding mode. Similarly, we would like to preserve the partial ordering between a GET from $CS and a floating-point operation, since a user code might want to examine the floating-point exception bits right after a given floating-point operation.<br><br>Another use-case we have is the following: we have a coprocessor that is turned on by setting a given bit on a system register. This can be accessed by a builtin. Such SET instruction must happen before using a coprocessor instruction - the compiler should not break that dependency when reordering instructions.<br><br>We have tried to implement this by using implicit Defs and implicit Uses in our instruction definitions, using for example `Defs = [CS] in` and `Uses = [CS]` where relevant in our Target Description files.<br><br>I have been running some experiments, examining the scheduling outputs and the dependencies (using VLIWScheduler in pre-RA, PostRASchedulerList in post-RA, and a child of VLIWPacketizerList for bundling).<br><br>I have found that the implicit defs and uses are indeed taken into account by the post-RA schedulers. However, they seem to be ignored by the pre-RA schedulers. Also, they do not appear as dependencies in the SelectionDAG.<br><br>If I look at what some other backends did, AArch64 does not seem to model anything on FPCR. PowerPC sets MFFS as scheduling barrier (isSchedulingBoundary) to prevent floating-point instructions being ordered above it - but isSchedulingBoundary seems to be only used by post-RA schedulers; pre-RA schedulers do not seem to care about that.<br><br>The bad consequence for us: our programmers have to encapsulate the SET instructions (touching system registers) in non-inlined functions to enforce the compiler not breaking anything.<br><br>We are looking for advice on how to treat this problem - we have possible leads, like modifying the SelectionDAG to recover these dependencies, or modifying the schedulers to scan the SelectionDAG and enforce the source order when such dependency is detected (maybe by having a look at how SourceScheduler works), but we have not yet investigated it fully.<br><br>Any such advice would be greatly appreciated<br><br>Also, another related issue: it would seem that the flag -ffp-exception-behavior=strict does not preserve the exception semantics like it says it does. Although the generated IR seems to preserve it, there does not seem to be anything in the LLVM backends enforcing the "strict" floating-point exception behavior.<br><br>That last point can be witnessed in that piece of code: https://godbolt.org/z/e96zP7jET<br><br>```<br>long fpcr;<br><br>int toto(float a, float b, float c, double d, double e){<br>  float bc = b + c; // first faddd<br>  asm("mrs %[result], FPCR" : [result] "=r" (fpcr) : :);<br>  float abc = a + bc; // second faddd<br>  float dw = (float) d; // fwidenlwd : should not happen before the second faddd<br>  float ew = (float) e;<br>  int dw_ewl = (int) dw + (int) ew;<br>  int abcl_dw_ewl = (int) abc + dw_ewl;<br>  return abcl_dw_ewl;<br>}<br><br>```<br><br>Compiling this piece of code with clang 11.0.0 for ARMv8-a gives the following assembly code:<br>```<br>toto:<br>        fadd    s1, s1, s2<br>        fcvt    s2, d3<br>        fadd    s0, s1, s0<br>        fcvt    s3, d4<br>        fcvtzs  w9, s2<br>        fcvtzs  w10, s0<br>        add     w9, w10, w9<br>        fcvtzs  w10, s3<br>        add     w0, w9, w10<br>        adrp    x9, fpcr<br>        //APP<br>        mrs     x8, FPCR<br>        //NO_APP<br>        str     x8, [x9, :lo12:fpcr]<br>        ret<br>```<br><br>Notice that mrs was moved below - which does not seem to preserve the floating-point exception semantics of the compiled code.<br></div></div><div style="font-family: "arial", "helvetica", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br data-mce-bogus="1"></div><div style="font-family: "arial", "helvetica", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">PS : apologies for the double message if any ; I sent the first to llvm-dev-bounces by mistake<br data-mce-bogus="1"></div><div style="font-family: "arial", "helvetica", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br><div>Best regards,</div><br><div><br> <div style="font-size: 9pt; font-family: "arial", "helvetica", sans-serif;"> <span style="color: rgb(20, 68, 68); font-size: 9pt;"><strong>Cyril Six</strong></span><br> <span style="color: rgb(20, 68, 68); font-size: 9pt;"><strong>Compiler Engineer • Kalray</strong></span><br> <span style="color: rgb(20, 68, 68); font-size: 8pt;">Phone: </span><br> <span style="color: rgb(17, 88, 143); font-size: 8pt;"><u>csix@kalrayinc.com</u> • <a href="https://www.kalrayinc.com" style="color: rgb(17, 88, 143);" rel="nofollow noopener noreferrer nofollow noopener noreferrer" target="_blank"><u>www.kalrayinc.com</u></a></span> </div> <br> <table cellpadding="0px" border="0px"><tbody><tr><td> <div> <a href="https://www.kalrayinc.com" rel="nofollow noopener noreferrer nofollow noopener noreferrer" target="_blank"> <img alt="Kalray logo" src="http://data.kalrayinc.com/Kalray_72.png" saveddisplaymode="" style=""></a> </div> </td></tr></tbody></table> <br>   <span style="color: rgb(125, 182, 33); font-size: 8pt; font-family: "arial", "helvetica", sans-serif;"><strong> Please consider the environment before printing this e-mail.</strong></span> <div> <span style="color: rgb(20, 68, 68); font-size: 8pt; font-family: "arial", "helvetica", sans-serif; display: block; line-height: 100%;">This message contains information that may be privileged or confidential and is the property of Kalray S.A. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.</span></div> </div></div></div><br></div></div><div id="content_out_csix_kalrayinc.com"></div></body></html>