<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>That answers that. MOV/CMP/CMOV is faster than CMP/CMOV/CMOV.
Thanks.</p>
<p>I've been finalising another peephole optimisation. What started
as a means to permit constants in CMOV instructions using a bit of
trickery became almost an entire rewrite of the optimisation if
only because I was struggling to remember which temporary variable
was set to what (where have we heard this before?!). I'm just
running my tests then will make a merge request explaining all of
the details. But these are the following additions:</p>
<p>* Aligns are now properly removed with the labels around the
JccMOV -> CMOV optimisations.<br>
* JccMOV -> CMOV will now work with constants in some
circumstances (although this won't be done under -Os as it adds
extra instructions).<br>
* If CMP/JE/MOV/@lbl is found, everything except the MOV is
removed if CMP and MOV contain the same operands (even if in
reverse order), since regardless of the result of the condition,
the end state is for the 2 operands (which might be registers,
references or constants) to be identical (MOV is only called if
they're not equal, and if MOV is not called, well, they're already
equal!), so we might as well just call MOV (the optimisation uses
MatchOperand to compare the operands, so if volatile references
are used, the optimisation is not made).<br>
</p>
<p>Gareth aka. Kit</p>
<p>P.S. Thanks for the godbolt link Florian. I just tried "return
(a>b) ? a : b;" and it compiles to the same thing, using a
MOV/CMP/CMOV triplet. In other words, it tries to convert a CMOV
to a MOV if it can.<br>
</p>
<div class="moz-cite-prefix">On 16/04/2022 20:03, Florian Klämpfl
via fpc-devel wrote:<br>
</div>
<blockquote type="cite"
cite="mid:8087EF67-714C-4FA7-B236-36CBB5B7E98F@freepascal.org">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">Am 16.04.2022 um 12:31 schrieb Thorsten Otto via
fpc-devel <<a
href="mailto:fpc-devel@lists.freepascal.org"
class="moz-txt-link-freetext" moz-do-not-send="true">fpc-devel@lists.freepascal.org</a>>:</div>
<br class="Apple-interchange-newline">
<div class="">
<meta charset="UTF-8" class="">
<div style="white-space: pre-wrap; caret-color: rgb(0, 0, 0); font-family: "Noto Sans"; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; margin: 0px;" class="">On Samstag, 16. April 2022 06:49:07 CEST J. Gareth Moreton via fpc-devel wrote:</div>
<div style="white-space: pre-wrap; caret-color: rgb(0, 0, 0); font-family: "Noto Sans"; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; margin: 0px;" class="">> but I haven't been able to find an authoritive</div>
<div style="white-space: pre-wrap; caret-color: rgb(0, 0, 0); font-family: "Noto Sans"; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; margin: 0px;" class="">> source on this yet.</div>
<p style="white-space: pre-wrap; caret-color: rgb(0, 0, 0); font-family: "Noto Sans"; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; margin: 0px;" class=""> </p>
<div style="white-space: pre-wrap; caret-color: rgb(0, 0, 0); font-family: "Noto Sans"; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; margin: 0px;" class="">Did you check what for example GCC generates for similar C constructs? I don't think it uses cmov at all.</div>
<p style="white-space: pre-wrap; caret-color: rgb(0, 0, 0); font-family: "Noto Sans"; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; margin: 0px;" class="">
</p>
</div>
</blockquote>
<br class="">
</div>
<div>Why shouldn’t it? clang does the same as my quick tests
recommends: <a href="https://godbolt.org/z/eWTvfcM8E"
class="moz-txt-link-freetext" moz-do-not-send="true">https://godbolt.org/z/eWTvfcM8E</a></div>
<br class="">
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-devel maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
<div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br />
<table style="border-top: 1px solid #D3D4DE;">
<tr>
<td style="width: 55px; padding-top: 13px;"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" width="46" height="29" style="width: 46px; height: 29px;" /></a></td>
<td style="width: 470px; padding-top: 12px; color: #41424e; font-size: 13px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;">Virus-free. <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank" style="color: #4453ea;">www.avast.com</a>
</td>
</tr>
</table><a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"> </a></div></body>
</html>