<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Thanks, I didn't that __builtin_assume existed in Clang.</p>
<p><br>
</p>
<p>So, IIRC to proceed with a patch, I should define a _LIBCPP_ASSUME macro wrapping it. Also, if I'm not mistaken, libc++ is sometimes used with g++ and MSVC, so the macro would either use __builtin_assume, __builtin_unreachable or __assume depending on the
 target. I guess that <algorithm> isn't the right place to put such a macro, but I don't know which is the right place.</p>
<p><br>
</p>
<p>Would you provide some guidance?</p>
<p><br>
</p>
<p>Thanks in advance :)</p>
<p><br>
</p>
<p>Morwenn<br>
</p>
<br>
<div style="color: rgb(0, 0, 0);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>De :</b> Hal Finkel <hfinkel@anl.gov><br>
<b>Envoyé :</b> lundi 31 octobre 2016 18:56<br>
<b>À :</b> Morwenn Ed<br>
<b>Cc :</b> cfe-dev@lists.llvm.org<br>
<b>Objet :</b> Re: [cfe-dev] Potential optimization for std::inplace_merge</font>
<div> </div>
</div>
<div>
<div style="font-family:arial,helvetica,sans-serif; font-size:10pt; color:#000000">
<br>
<hr id="zwchr">
<blockquote style="border-left:2px solid rgb(16,16,255); margin-left:5px; padding-left:5px; color:rgb(0,0,0); font-weight:normal; font-style:normal; text-decoration:none; font-family:Helvetica,Arial,sans-serif; font-size:12pt">
<b>From: </b>"Morwenn Ed via cfe-dev" <cfe-dev@lists.llvm.org><br>
<b>To: </b>cfe-dev@lists.llvm.org<br>
<b>Sent: </b>Thursday, October 27, 2016 2:12:39 PM<br>
<b>Subject: </b>[cfe-dev] Potential optimization for std::inplace_merge<br>
<br>
<div id="divtagdefaultwrapper" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif">
[...]
<p></p>
<p><br>
</p>
<p>However, at this point, the new "optimization" made the code dramatically slower than it was before when sorting a vector of one million integers with a mergesort built on the top of
<span style="font-family:"Courier New",monospace">std::inplace_merge</span>. It kind of baffled me until I finally noticed that the second loop had some information that the first didn't have: the second loop knows that
<span style="font-family:"Courier New",monospace">first1 != last1</span> and <span style="font-family:"Courier New",monospace">
first2 != last2</span> while it runs. However, it is apparently possible to give that information to the first loop too. I defined the following macro:</p>
<p><br>
</p>
<p><span id="DWT3344" style="font-family:"Courier New",monospace">    #define ASSUME(cond) do { if (!(cond)) __builtin_unreachable(); } while(0)</span></p>
</div>
</blockquote>
FYI, for Clang, you'll need to use __builtin_assume(cond) (http://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions).<br>
<br>
 -Hal<br>
<blockquote style="border-left:2px solid rgb(16,16,255); margin-left:5px; padding-left:5px; color:rgb(0,0,0); font-weight:normal; font-style:normal; text-decoration:none; font-family:Helvetica,Arial,sans-serif; font-size:12pt">
<div id="divtagdefaultwrapper" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif">
<p><span style="font-family:"Courier New",monospace"></span></p>
<p><span><br>
</span></p>
[...]
<p></p>
<p></p>
</div>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
cfe-dev@lists.llvm.org<br>
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br>
</blockquote>
<br>
<br>
<br>
-- <br>
<div><span name="x"></span>Hal Finkel<br>
Lead, Compiler Technology and Programming Languages<br>
Leadership Computing Facility<br>
Argonne National Laboratory<span name="x"></span><br>
</div>
</div>
</div>
</div>
</div>
</body>
</html>