From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B28D13858416; Thu, 29 Jun 2023 20:46:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B28D13858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688071596; bh=GLVseLMY0bpedRpipQ8WvUlO91QZT3j1LHXfUuJe8pE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=T2gxk6om4FvUKGsM3UPxiQ0hmci4qHzv8o61DqbqCCuiAB7Ka9j/RF9AL7Z1ZBAgY we9UFeDkBMNtcMv8kiSTri0m30xwjSTohimwvynHKI+jTouLOFbxJ5jGmuU/W3VC+6 AAi/uW37M/rcdCHNlQtjB6bspG+sd+A8ZcHbGzdw= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/109849] suboptimal code for vector walking loop Date: Thu, 29 Jun 2023 20:46:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109849 --- Comment #19 from CVS Commits --- The master branch has been updated by Jan Hubicka : https://gcc.gnu.org/g:9dc18fca431626404b0692c689a2e103666e7adb commit r14-2202-g9dc18fca431626404b0692c689a2e103666e7adb Author: Jan Hubicka Date: Thu Jun 29 22:45:37 2023 +0200 Compute ipa-predicates for conditionals involving __builtin_expect_p std::vector allocator looks as follows: __attribute__((nodiscard)) struct pair * std::__new_allocator >::allocate (struct __new_allocator * const this, size_type __n, const void= * D.27753) { bool _1; long int _2; long int _3; long unsigned int _5; struct pair * _9; [local count: 1073741824]: _1 =3D __n_7(D) > 1152921504606846975; _2 =3D (long int) _1; _3 =3D __builtin_expect (_2, 0); if (_3 !=3D 0) goto ; [10.00%] else goto ; [90.00%] [local count: 107374184]: if (__n_7(D) > 2305843009213693951) goto ; [50.00%] else goto ; [50.00%] [local count: 53687092]: std::__throw_bad_array_new_length (); [local count: 53687092]: std::__throw_bad_alloc (); [local count: 966367641]: _5 =3D __n_7(D) * 8; _9 =3D operator new (_5); return _9; } So there is check for allocated block size being greater than max_size which is wrapper in __builtin_expect. This makes ipa-fnsummary to give up analy= zing predicates and it will miss the fact that the two different calls to __throw will be optimized out if __n is larady smaller than 1152921504606846975 which it is after _M_check_len. This patch extends ipa-fnsummary to understand functions that return th= eir parameter. gcc/ChangeLog: PR tree-optimization/109849 * ipa-fnsummary.cc (decompose_param_expr): Skip functions returning its parameter. (set_cond_stmt_execution_predicate): Return early if predicate was constructed. gcc/testsuite/ChangeLog: PR tree-optimization/109849 * gcc.dg/ipa/pr109849.c: New test.=