public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "richard.yao at alumni dot stonybrook.edu" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/110007] Implement support for Clang’s __builtin_unpredictable() Date: Sat, 27 May 2023 18:19:19 +0000 [thread overview] Message-ID: <bug-110007-4-4fTVvHUOz7@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-110007-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110007 --- Comment #3 from Richard Yao <richard.yao at alumni dot stonybrook.edu> --- (In reply to Andrew Pinski from comment #2) > (In reply to Richard Yao from comment #0) > > Having the ability to specify __builtin_unpredictable() as a hint to > > encourage the compiler to use cmov would be useful for implementing > > algorithms like binary search that have unpredictable branches. > > __builtin_expect_with_probability() looks like a possible substitute, but > > Clang does not support it and it does not always work as described in > > #110001. > > PR 110001 has nothing to do with __builtin_expect_with_probability and I mentioned it briefly in PR 110001, but I guess I should make it explicit. See line 58 here: https://gcc.godbolt.org/z/ef3Yfchzv That is made into a jump, when all that is necessary is cmov, which is what Clang generates. In the example I had posted in PR 110001, I had not used __builtin_expect_with_probability() because it made no difference, but here I am using it to show that cmov is not used. Earlier in the output, GCC 12.3 uses cmov for every 3rd instruction, so I suspect that this is not a case of two cmovs being too close to each other. Should I file another issue explicitly for that so this could be left for the request that we have __builtin_unpredictable()? > __builtin_expect_with_probability will do exactly the same as > __builtin_unpredictable will do really. __builtin_unpredictable() is easier to read than __builtin_expect_with_probability() and it would be nice for both Clang and GCC to support the same builtins.
next prev parent reply other threads:[~2023-05-27 18:19 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-27 17:54 [Bug c/110007] New: " richard.yao at alumni dot stonybrook.edu 2023-05-27 17:59 ` [Bug c/110007] " pinskia at gcc dot gnu.org 2023-05-27 18:01 ` pinskia at gcc dot gnu.org 2023-05-27 18:19 ` richard.yao at alumni dot stonybrook.edu [this message] 2023-05-27 18:25 ` pinskia at gcc dot gnu.org 2023-05-27 20:26 ` richard.yao at alumni dot stonybrook.edu 2023-05-28 5:42 ` amonakov at gcc dot gnu.org 2023-05-28 16:21 ` hubicka at gcc dot gnu.org 2023-05-28 21:37 ` richard.yao at alumni dot stonybrook.edu 2023-05-30 7:49 ` rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-110007-4-4fTVvHUOz7@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).