[cfe-dev] Potential optimization for std::inplace_merge

Morwenn Ed via cfe-dev cfe-dev at lists.llvm.org
Thu Nov 3 08:19:06 PDT 2016


Thanks, I didn't that __builtin_assume existed in Clang.


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.


Would you provide some guidance?


Thanks in advance :)


Morwenn

________________________________
De : Hal Finkel <hfinkel at anl.gov>
Envoyé : lundi 31 octobre 2016 18:56
À : Morwenn Ed
Cc : cfe-dev at lists.llvm.org
Objet : Re: [cfe-dev] Potential optimization for std::inplace_merge


________________________________
From: "Morwenn Ed via cfe-dev" <cfe-dev at lists.llvm.org>
To: cfe-dev at lists.llvm.org
Sent: Thursday, October 27, 2016 2:12:39 PM
Subject: [cfe-dev] Potential optimization for std::inplace_merge

[...]


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 std::inplace_merge. 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 first1 != last1 and first2 != last2 while it runs. However, it is apparently possible to give that information to the first loop too. I defined the following macro:


    #define ASSUME(cond) do { if (!(cond)) __builtin_unreachable(); } while(0)

FYI, for Clang, you'll need to use __builtin_assume(cond) (http://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions).

 -Hal


[...]

_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161103/1b5717e0/attachment.html>


More information about the cfe-dev mailing list