From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BEB623896C30; Wed, 4 Nov 2020 11:15:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEB623896C30 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/97690] (cond ? 2 : 0) is not optimized to int(cond) << 1 Date: Wed, 04 Nov 2020 11:15:45 +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: 11.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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: Wed, 04 Nov 2020 11:15:45 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97690 --- Comment #5 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:3e190757fa332d327bee27495f37beb01155cfab commit r11-4717-g3e190757fa332d327bee27495f37beb01155cfab Author: Jakub Jelinek Date: Wed Nov 4 11:55:29 2020 +0100 phiopt: Optimize x ? 1024 : 0 to (int) x << 10 [PR97690] The following patch generalizes the x ? 1 : 0 -> (int) x optimization to handle also left shifts by constant. During x86_64-linux and i686-linux bootstraps + regtests it triggered in 1514 unique non-LTO -m64 cases (sort -u on log mentioning filename, function name and shift count) and 1866 -m32 cases. Unfortunately, the patch regresses (before the tests have been adjusted= ): +FAIL: gcc.dg/tree-ssa/ssa-ccp-11.c scan-tree-dump-times optimized "if = " 0 +FAIL: gcc.dg/vect/bb-slp-pattern-2.c -flto -ffat-lto-objects=20 scan-tree-dump-times slp1 "optimized: basic block" 1 +FAIL: gcc.dg/vect/bb-slp-pattern-2.c scan-tree-dump-times slp1 "optimi= zed: basic block" 1 and in both cases it actually results in worse code. > > We'd need some optimization that would go through all PHI edges and > > compute if some use of the phi results don't actually compute a constant > > across all the PHI edges - 1 & 0 and 0 & 1 is always 0. > PRE should do this, IMHO only optimizing it at -O2 is fine. > > Similarly, in the slp vectorization test there is: > > a[0] =3D b[0] ? 1 : 7; > note this, carefully avoiding the already "optimized" b[0] ? 1 : 0 ... > So the option is to put : 7 in the 2, 4 an 8 case as well. The testc= ase > wasn't added for any real-world case but is artificial I guess for > COND_EXPR handling of invariants. > But yeah, for things like SLP it means we eventually have to > implement reverse transforms for all of this to make the lanes > matching. But that's true anyway for things like x + 1 vs. x + 0 > or x / 3 vs. x / 2 or other simplifications we do. 2020-11-04 Jakub Jelinek PR tree-optimization/97690 * tree-ssa-phiopt.c (conditional_replacement): Also optimize cond ? pow2p_cst : 0 as ((type) cond) << cst. * gcc.dg/tree-ssa/phi-opt-22.c: New test. * gcc.dg/tree-ssa/ssa-ccp-11.c: Use -O2 instead of -O1. * gcc.dg/vect/bb-slp-pattern-2.c (foo): Use ? 2 : 7, ? 4 : 7 and ? 8 : 7 instead of ? 2 : 0, ? 4 : 0, ? 8 : 0.=