From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5AA6538515F4; Wed, 21 Apr 2021 08:35:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5AA6538515F4 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/100162] missed optimization for dead code elimination at -O3 (vs. -O2) Date: Wed, 21 Apr 2021 08:35:46 +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: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth 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: version cc everconfirmed cf_reconfirmed_on bug_status keywords 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, 21 Apr 2021 08:35:46 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100162 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Version|unknown |12.0 CC| |rguenth at gcc dot gnu.org Ever confirmed|0 |1 Last reconfirmed| |2021-04-21 Status|UNCONFIRMED |NEW Keywords| |missed-optimization --- Comment #1 from Richard Biener --- Optimized by DOM3 which sees the following difference: - [local count: 118111601]: + [local count: 955630225]: b.1_1 =3D b; - c[0][b.1_1] =3D 2; - c[1][b.1_1] =3D 2; - c[2][b.1_1] =3D 2; - c[3][b.1_1] =3D 2; + _27 =3D (sizetype) b.1_1; + _28 =3D _27 * 4; + vectp_c.13_26 =3D &c + _28; + MEM [(int *)vectp_c.13_26] =3D { 2, 2, 2, 2 }; + vectp_c.12_30 =3D vectp_c.13_26 + 16; c[4][b.1_1] =3D 2; a =3D 5; _5 =3D b.1_1 !=3D 0; _6 =3D (int) _5; - _8 =3D _6 / 2; + _7 =3D c[0][0]; + _8 =3D _6 / _7; if (_8 !=3D 0) here c[0][b.1_1] takes advantage of get_ref_base_and_extent honoring the kn= own array size of [1] while the pointer based access is not constrained this way which makes matching c[0][0] to *(&c + _28) =3D { 2, 2, 2, 2 } difficult. The realistic chance is to catch this by improving value-numbering done on the not unrolled loop earlier: [local count: 955630225]: # a.3_19 =3D PHI <_2(3), 0(2)> c[a.3_19][b.1_1] =3D 2; _2 =3D a.3_19 + 1; if (_2 <=3D 4) goto ; [89.00%] else goto ; [11.00%] [local count: 118111600]: a =3D _2; _5 =3D b.1_1 !=3D 0; _6 =3D (int) _5; _7 =3D c[0][0]; where we could use SCEV & friends to lookup c[0][0] at the c[a.3_19][b.1_1] definition in vn_reference_lookup_3. That might also help to look through loop abstraction earlier.=