From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 90329383F40E; Thu, 24 Jun 2021 06:40:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 90329383F40E From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/101179] y % (x ? 16 : 4) and y % (4 << (2 * (bool)x)) produce different code Date: Thu, 24 Jun 2021 06:40:24 +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: enhancement 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: blocked 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: Thu, 24 Jun 2021 06:40:24 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101179 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |85316 --- Comment #6 from Richard Biener --- (In reply to Jonathan Wakely from comment #1) > On IRC Richi said: "VRP has code to do that but maybe for some reason shi= fts > are not handled" Specifically simplify_using_ranges::simplify has /* Convert: LHS =3D CST BINOP VAR Where VAR is two-valued and LHS is used in GIMPLE_COND only To: LHS =3D VAR =3D=3D VAL1 ? (CST BINOP VAL1) : (CST BINOP VAL2) Also handles: LHS =3D VAR BINOP CST Where VAR is two-valued and LHS is used in GIMPLE_COND only To: LHS =3D VAR =3D=3D VAL1 ? (VAL1 BINOP CST) : (VAL2 BINOP CST) */ restrictions that stand in the way: if (TREE_CODE_CLASS (rhs_code) =3D=3D tcc_binary ... && single_imm_use (lhs, &use_p, &use_stmt) && gimple_code (use_stmt) =3D=3D GIMPLE_COND) VRP1 sees [local count: 1073741824]: _1 =3D y_7(D) % 100; x_8 =3D _1 =3D=3D 0; _2 =3D (int) x_8; _3 =3D _2 * 2; _4 =3D 4 << _3; _5 =3D y_7(D) % _4; _6 =3D _5 =3D=3D 0;=20 _9 =3D (int) _6; return _9;=20 so it would consider _2 * 2 but its single use is in a shift, the condition is after another op, the modulo, and there the condition is in an assignment, not in a GIMPLE_COND. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D85316 [Bug 85316] [meta-bug] VRP range propagation missed cases=