public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/109849] suboptimal code for vector walking loop Date: Fri, 30 Jun 2023 14:28:14 +0000 [thread overview] Message-ID: <bug-109849-4-YW9ZWHk3YH@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-109849-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109849 --- Comment #20 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jan Hubicka <hubicka@gcc.gnu.org>: https://gcc.gnu.org/g:eab57b825bcc350e9ff44eb2fa739a80199d9bb1 commit r14-2219-geab57b825bcc350e9ff44eb2fa739a80199d9bb1 Author: Jan Hubicka <jh@suse.cz> Date: Fri Jun 30 16:27:27 2023 +0200 Fix handling of __builtin_expect_with_probability and improve first-match heuristics While looking into the std::vector _M_realloc_insert codegen I noticed that call of __throw_bad_alloc is predicted with 10% probability. This is because the conditional guarding it has __builtin_expect (cond, 0) on it. This incorrectly takes precedence over more reliable heuristics predicting that call to cold noreturn is likely not going to happen. So I reordered the predictors so __builtin_expect_with_probability comes first after predictors that never makes a mistake (so user can use it to always specify the outcome by hand). I also downgraded malloc predictor since I do think user-defined malloc functions & new operators may behave funny ways and moved usual __builtin_expect after the noreturn cold predictor. This triggered latent bug in expr_expected_value_1 where if (*predictor < predictor2) *predictor = predictor2; should be: if (predictor2 < *predictor) *predictor = predictor2; which eventually triggered an ICE on combining heuristics. This made me notice that we can do slightly better while combining expected values in case only one of the parameters (such as in a*b when we expect a==0) can determine overall result. Note that the new code may pick weaker heuristics in case that both values are predicted. Not sure if this scenario is worth the extra CPU time: there is not correct way to combine the probabilities anyway since we do not know if the predictions are independent, so I think users should not rely on it. Fixing this issue uncovered another problem. In 2018 Martin Liska added code predicting that MALLOC returns non-NULL but instead of that he predicts that it returns true (boolean 1). This sort of works for testcase testing malloc (10) != NULL but, for example, we will predict malloc (10) == malloc (10) as true, which is not right and such comparsion may happen in real code I think proper way is to update expr_expected_value_1 to work with value ranges, but that needs greater surgery so I decided to postpone this and only add FIXME and fill PR110499. gcc/ChangeLog: PR middle-end/109849 * predict.cc (estimate_bb_frequencies): Turn to static function. (expr_expected_value_1): Fix handling of binary expressions with predicted values. * predict.def (PRED_MALLOC_NONNULL): Move later in the priority queue. (PRED_BUILTIN_EXPECT_WITH_PROBABILITY): Move to almost top of the priority queue. * predict.h (estimate_bb_frequencies): No longer declare it. gcc/testsuite/ChangeLog: PR middle-end/109849 * gcc.dg/predict-18.c: Improve testcase.
next prev parent reply other threads:[~2023-06-30 14:28 UTC|newest] Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-13 22:26 [Bug middle-end/109849] New: " hubicka at gcc dot gnu.org 2023-05-13 22:32 ` [Bug middle-end/109849] " pinskia at gcc dot gnu.org 2023-05-13 22:40 ` pinskia at gcc dot gnu.org 2023-05-14 5:57 ` amonakov at gcc dot gnu.org 2023-05-14 9:58 ` hubicka at ucw dot cz 2023-05-14 10:01 ` hubicka at ucw dot cz 2023-05-15 6:56 ` rguenth at gcc dot gnu.org 2023-05-17 14:53 ` hubicka at gcc dot gnu.org 2023-05-17 20:36 ` rguenth at gcc dot gnu.org 2023-05-18 9:35 ` hubicka at gcc dot gnu.org 2023-05-18 11:54 ` rguenth at gcc dot gnu.org 2023-05-18 13:00 ` hubicka at gcc dot gnu.org 2023-05-23 9:57 ` cvs-commit at gcc dot gnu.org 2023-05-23 10:10 ` rguenth at gcc dot gnu.org 2023-05-24 11:19 ` cvs-commit at gcc dot gnu.org 2023-06-16 14:20 ` hubicka at gcc dot gnu.org 2023-06-18 16:59 ` cvs-commit at gcc dot gnu.org 2023-06-19 16:28 ` cvs-commit at gcc dot gnu.org 2023-06-26 16:30 ` cvs-commit at gcc dot gnu.org 2023-06-28 9:47 ` cvs-commit at gcc dot gnu.org 2023-06-29 20:46 ` cvs-commit at gcc dot gnu.org 2023-06-30 14:28 ` cvs-commit at gcc dot gnu.org [this message] 2023-11-19 15:25 ` hubicka at gcc dot gnu.org 2023-11-21 14:17 ` cvs-commit at gcc dot gnu.org 2023-11-21 15:12 ` hubicka at gcc dot gnu.org 2023-11-24 16:35 ` cvs-commit at gcc dot gnu.org 2023-11-24 17:00 ` cvs-commit at gcc dot gnu.org 2023-11-24 17:00 ` jamborm at gcc dot gnu.org 2023-11-27 14:39 ` rguenth at gcc dot gnu.org 2023-11-28 9:33 ` redi at gcc dot gnu.org 2023-11-28 10:32 ` jamborm at gcc dot gnu.org 2023-11-28 12:41 ` redi at gcc dot gnu.org 2023-11-28 13:29 ` redi at gcc dot gnu.org 2023-11-28 15:29 ` redi at gcc dot gnu.org 2023-11-28 22:21 ` redi at gcc dot gnu.org 2023-11-29 12:27 ` hubicka at ucw dot cz 2023-11-29 15:25 ` cvs-commit at gcc dot gnu.org 2024-01-03 17:41 ` jamborm at gcc dot gnu.org 2024-05-30 11:11 ` redi at gcc dot gnu.org 2024-06-03 19:38 ` cvs-commit at gcc dot gnu.org 2024-06-03 19:54 ` cvs-commit 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-109849-4-YW9ZWHk3YH@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).