From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 516A53858D28; Tue, 27 Jun 2023 09:34:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 516A53858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687858472; bh=mVkbpCQ+vW2YpobGIoar83jEIseZum+KM6/KhbL04ss=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QSSmcCbzrKe1FYVn9CPRPlMBuwLNoe/yConWNClzf6vCq8zPF7VbBWWgOjg8om0Op H2WTTspisLPoUmqL+dz1J/qTA8IljJTq+9mGEXN17clawoGEXtOJ2NtFttvWu5OA9v xOnKq4rLXTn9hdKBczo6/I/aiO36eo0XtxbYhzjA= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110413] [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-1880-g827e208fa64 Date: Tue, 27 Jun 2023 09:34:31 +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: 14.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: 14.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status everconfirmed cf_known_to_work cf_reconfirmed_on 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=3D110413 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Known to work| |11.4.0, 12.3.0 Last reconfirmed| |2023-06-27 --- Comment #1 from Richard Biener --- GCC 13 eliminates the call in DOM3. The differences into that pass are qui= te big with trunk having performed many more optimizations, in particular we have elided the __builtin_unreachable () call already in DOM2 where the first differences appears. We now manage to simplify the _24 !=3D 0 branch. @@ -79,22 +80,15 @@ _22 =3D _2 <=3D &d; _23 =3D _2 !=3D 0B; _24 =3D _23 & _22; - if (_24 !=3D 0) - goto ; [100.00%] - else - goto ; [0.00%] + goto ; [100.00%] [local count: 850510901]: k =3D _2; _3 =3D 1; _1 =3D 1; _15 =3D 1; - goto ; [100.00%] - - [count: 0]: - __builtin_unreachable (); - [local count: 955630225]: + [local count: 955630225]: So we manage to optimize [local count: 105119324]: k =3D _2; _22 =3D _2 <=3D &d; _23 =3D _2 !=3D 0B; _24 =3D _23 & _22; if (_24 !=3D 0) goto ; [100.00%] else goto ; [0.00%] [local count: 850510901]: k =3D _2; _3 =3D _2 <=3D &d; _1 =3D _2 !=3D 0B; _15 =3D _1 & _3; if (_15 !=3D 0) goto ; [100.00%] else goto ; [0.00%] [count: 0]: __builtin_unreachable (); [local count: 955630225]: # h.4_25 =3D PHI _4 =3D h.4_25 + -1; h =3D _4; h.4_5 =3D h; if (h.4_5 !=3D 0) goto ; [89.00%] It seems we're now doing this based on the exported global range table since we correctly first arrive at Optimizing block #3 Optimizing statement k =3D _2;=20 LKUP STMT k =3D _2 with .MEM_11 LKUP STMT _2 =3D k with .MEM_11 LKUP STMT _2 =3D k with .MEM_21=20 2>>> STMT _2 =3D k with .MEM_21 Optimizing statement _22 =3D _2 <=3D &d;=20 LKUP STMT _22 =3D _2 le_expr &d 2>>> STMT _22 =3D _2 le_expr &d LKUP STMT _2 ge_expr &d Optimizing statement _23 =3D _2 !=3D 0B; LKUP STMT _23 =3D _2 ne_expr 0B 2>>> STMT _23 =3D _2 ne_expr 0B Optimizing statement _24 =3D _23 & _22; LKUP STMT _24 =3D _23 bit_and_expr _22 2>>> STMT _24 =3D _23 bit_and_expr _22 Optimizing statement if (_24 !=3D 0) Visiting conditional with predicate: if (_24 !=3D 0) With known ranges _24: [irange] _Bool VARYING Predicate evaluates to: DON'T KNOW but then we register global ranges from the __builtin_unreachable () CFG: # RANGE [irange] _Bool [1, 1] _24 =3D _23 & _22; and CFG cleanup scheduled by DOM does static bool cleanup_control_expr_graph (basic_block bb, gimple_stmt_iterator gsi) { ... case GIMPLE_COND: { gimple_match_op res_op; if (gimple_simplify (stmt, &res_op, NULL, no_follow_ssa_edges, no_follow_ssa_edges) && res_op.code =3D=3D INTEGER_CST) val =3D res_op.ops[0]; which now picks this up and elides the branch. For some reason the "dead" stmts [local count: 118111600]: # PT =3D nonlocal null=20 _2 =3D j ();=20 i =3D _2; k =3D _2; # RANGE [irange] _Bool [1, 1] _22 =3D _2 <=3D &d;=20 # RANGE [irange] _Bool [1, 1] _23 =3D _2 !=3D 0B; # RANGE [irange] _Bool [1, 1] _24 =3D _23 & _22; allow us to optimize k =3D _2; # PT =3D nonlocal escaped null k.5_6 =3D k; _16 =3D k.5_6 =3D=3D &g; _17 =3D k.5_6 !=3D 0B; _18 =3D _17 | _16; if (_18 !=3D 0) via Optimizing statement _16 =3D k.5_6 =3D=3D &g; Replaced 'k.5_6' with variable '_2' LKUP STMT _16 =3D _2 eq_expr &g 2>>> STMT _16 =3D _2 eq_expr &g Optimizing statement _17 =3D k.5_6 !=3D 0B; Replaced 'k.5_6' with variable '_2' LKUP STMT _17 =3D _2 ne_expr 0B FIND: _23 Replaced redundant expr '_2 !=3D 0B' with '_23' =3D=3D=3D=3D ASGN _17 =3D _23 Optimizing statement _18 =3D _17 | _16; Replaced '_17' with variable '_23' Folded to: _18 =3D _16 | _23; LKUP STMT _18 =3D _16 bit_ior_expr _23 2>>> STMT _18 =3D _16 bit_ior_expr _23 Optimizing statement if (_18 !=3D 0) Replaced '_18' with constant '1' so it's kind of a missed optimization in the first DOM that elides the stmts and the inability of ranger to capture the relations in the global ranges.=