From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 404643858C54; Thu, 22 Jun 2023 21:01:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 404643858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687467696; bh=1oNVbMFg+msLLZvxuSNXRAKS5NLfFrexkeZ0jqIfSU0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=K8uoQYzPQvQGL72dHFKAGmh8j8ddKsI04xsMtFGMS/cF96iAm2waSOBM3+Z+3jTkU KNiI11iMjd3/+Zyglif/57V8+zto3O2w3hPOotvUvjDYpX3QEn7oX+JEcxuNSW+Moz 1/zs6UvZR1DbJUA7JhTDpX9xVykfP6xZ1+Dqa/c8= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/110369] [14 Regression] wrong code on x86_64-linux-gnu with sel-scheduling Date: Thu, 22 Jun 2023 21:01:35 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: unknown X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia 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: 14.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: short_desc component 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=3D110369 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|[14 Regression] wrong code |[14 Regression] wrong code |on x86_64-linux-gnu |on x86_64-linux-gnu with | |sel-scheduling Component|tree-optimization |rtl-optimization --- Comment #3 from Andrew Pinski --- The first difference (after my patch) is in VRP: Before: ``` Folding statement: f_14 =3D f_20 + 1; Loops range found for f_20: [irange] int [0, 1] NONZERO 0x1 and calculat= ed range :[irange] int [0, 1] NONZERO 0x1 Matching expression match.pd:2404, gimple-match.cc:852 Matching expression match.pd:2407, gimple-match.cc:925 Matching expression match.pd:2414, gimple-match.cc:985 Matching expression match.pd:1924, gimple-match.cc:802 Matching expression match.pd:1896, gimple-match.cc:720 Global Exported: f_14 =3D [irange] int [1, 2] NONZERO 0x3 Folded into: f_14 =3D _18 ? 1 : 2; ``` After: ``` Folding statement: f_14 =3D f_20 + 1; Loops range found for f_20: [irange] int [0, 1] NONZERO 0x1 and calculat= ed range :[irange] int [0, 1] NONZERO 0x1 Matching expression match.pd:2404, gimple-match.cc:852 Matching expression match.pd:2407, gimple-match.cc:925 Matching expression match.pd:2414, gimple-match.cc:985 Matching expression match.pd:1924, gimple-match.cc:802 Applying pattern match.pd:4720, gimple-match.cc:11377 Applying pattern match.pd:3998, gimple-match.cc:39957 gimple_simplified to _8 =3D f_20 + 1; f_14 =3D _8; Registering value_relation (_8 > f_20) (bb12) at _8 =3D f_20 + 1; Registering value_relation (f_14 =3D=3D _8) (bb12) at f_14 =3D _8; Global Exported: f_14 =3D [irange] int [1, 2] NONZERO 0x3 Folded into: f_14 =3D _8; ``` Note _18 is defined as: _18 =3D f_20 =3D=3D 0; Which is ok and 100% correct. And then another difference: Before: ``` Folding statement: if (f_14 !=3D 2) Visiting conditional with predicate: if (f_14 !=3D 2) With known ranges f_14: [irange] int [1, 2] NONZERO 0x3 Predicate evaluates to: DON'T KNOW Matching expression match.pd:2404, gimple-match.cc:852 Matching expression match.pd:2407, gimple-match.cc:925 Matching expression match.pd:2414, gimple-match.cc:985 Applying pattern match.pd:5945, gimple-match.cc:24663 Matching expression match.pd:1924, gimple-match.cc:802 Applying pattern match.pd:4600, gimple-match.cc:176366 Applying pattern match.pd:3998, gimple-match.cc:39802 gimple_simplified to if (_18 !=3D 0) Folded into: if (_18 !=3D 0) ``` After: ``` Folding statement: if (f_14 !=3D 2) Visiting conditional with predicate: if (f_14 !=3D 2) With known ranges f_14: [irange] int [1, 2] NONZERO 0x3 Predicate evaluates to: DON'T KNOW Matching expression match.pd:2404, gimple-match.cc:852 Matching expression match.pd:2407, gimple-match.cc:925 Matching expression match.pd:2414, gimple-match.cc:985 Not folded ``` I don't get why VRP folded it differently. Anyways we just have a missed optimization inside VRP after my commit, not wrong code. The wrong code is due to sel scheduling. The code at .optimized: Before: ``` if (f_20 =3D=3D 0) ``` After: ``` # RANGE [irange] int [-INF, +INF] NONZERO 0x3 _8 =3D f_20 + 1; if (_8 !=3D 2) ``` (which is basically f_21 !=3D 1 or rather f_21 =3D=3D 0 here)=