From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B89EF385840F; Wed, 6 Apr 2022 06:15:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B89EF385840F From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/105142] [12 Regression] Wrong code with -O2 since r12-2591 Date: Wed, 06 Apr 2022 06:15:06 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Apr 2022 06:15:06 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105142 --- Comment #12 from CVS Commits --- The master branch has been updated by Richard Biener : https://gcc.gnu.org/g:fc8d9e4497032dd295aac9414042163f92250b77 commit r12-8012-gfc8d9e4497032dd295aac9414042163f92250b77 Author: Richard Biener Date: Mon Apr 4 12:23:28 2022 +0200 tree-optimization/105142 - wrong code with maybe_fold_{and,or}_comparis= ons The following avoids expanding definitions in regions conditionally executed under the condition A when simplifying A && B or A || B. This is done by passing down the basic-block of the outer condition to maybe_fold_{and,or}_comparisons, through the various helpers in gimple-fold.cc that might call back to maybe_fold_{and,or}_compariso= ns and ultimatively to maybe_fold_comparisons_from_match_pd where the fix is to provide a custom valueization hook to gimple_match_op::resimplify that avoids looking at definitions that do not dominate the outer block. For the testcase this avoids combining a stmt that invokes undefined integer overflow when the outer condition is false but it also aovids combining stmts with range information that is derived from the outer condition. The new parameter to maybe_fold_{and,or}_comparisons is defaulted to nullptr and I only adjusted the if-combine to pass down the outer block. I think other callers like tree-if-conv have the same issue but it's not straight-forward as to what to do there. 2022-04-05 Richard Biener PR tree-optimization/105142 * gimple-fold.h (maybe_fold_and_comparisons): Add defaulted basic-block parameter. (maybe_fold_or_comparisons): Likewise. * gimple-fold.cc (follow_outer_ssa_edges): New. (maybe_fold_comparisons_from_match_pd): Use follow_outer_ssa_ed= ges when an outer condition basic-block is specified. (and_comparisons_1, and_var_with_comparison, and_var_with_comparison_1, or_comparisons_1, or_var_with_comparison, or_var_with_comparison_1): Receive and = pass down the outer condition basic-block. * tree-ssa-ifcombine.cc (ifcombine_ifandif): Pass down the basic-block of the outer condition. * g++.dg/torture/pr105142.C: New testcase.=