From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 05A3D3857C47; Mon, 8 Nov 2021 11:12:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05A3D3857C47 From: "aldyh at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103120] [12 Regression] test miscompiled with -O2 since r12-4790 Date: Mon, 08 Nov 2021 11:12:50 +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: aldyh at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned 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: Mon, 08 Nov 2021 11:12:51 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103120 --- Comment #5 from Aldy Hernandez --- This is an ordering issue in the path solver, and it's not even relation related! How interesting. ./xgcc -B./ a.c -O2 -fdisable-tree-ethread -fdisable-tree-thread1 -fdisable-tree-thread2 -fdisable-tree-threadfull1 -fno-tree-dominator-opts -fdump-tree-threadfull2-details-threading -fdbg-cnt=3Dback_threadfull2:1-1 The path is 19->3->??: [local count: 916928331]: # value_20 =3D PHI # n_27 =3D PHI n_16 =3D n_27 + 4; value_17 =3D value_20 / 10000; if (value_20 > 42949672959999) goto ; [89.00%] else goto ; [11.00%] The path solver calculates: *********** path_range_query ****************** path_range_query: compute_ranges for path: BB 19, BB 3 Registering killing_def (path_oracle) value_17 range_defined_in_block (BB3) for value_20 is long unsigned int [4294967296, 1844674407370955] range_defined_in_block (BB3) for value_17 is long unsigned int [429496, 184467440737] range_defined_in_block (BB3) for value_20 is long unsigned int [429496, 184467440737] So, it's calculating the range for value_20 as it tries to resolve value_17= .=20 The first 2 ranges are correct. Then it tries to calculate the range for value_20 (again) because it's an import. However, when looking at the PHI, it ignores that there's already a cache entry, so it tries the following... # value_20 =3D PHI ...using the new value of value_17 which is incorrect. It blows my mind that we haven't run into this before, especially with such= a simple test case. I need to think about this, but my gut feeling says the following should do= it: diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index 9175651e896..7b5b2e5e55d 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -356,7 +356,8 @@ path_range_query::compute_ranges_in_block (basic_block = bb) { tree name =3D ssa_name (i); - if (range_defined_in_block (r, name, bb)) + if (!bitmap_bit_p (m_has_cache_entry, SSA_NAME_VERSION (name)) + && range_defined_in_block (r, name, bb)) set_cache (r, name); }=