From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8625 invoked by alias); 4 Mar 2015 13:44:33 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 8561 invoked by uid 48); 4 Mar 2015 13:44:30 -0000 From: "maltsevm at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/65307] [4.9 Regression] Incorrect optimization breaks basic arithmetic Date: Wed, 04 Mar 2015 13:44:00 -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: 4.9.2 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: maltsevm at gmail dot com X-Bugzilla-Status: REOPENED X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.9.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-03/txt/msg00491.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65307 Mikhail Maltsev changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maltsevm at gmail dot com --- Comment #8 from Mikhail Maltsev --- A simpler testcase: static inline unsigned cp(unsigned x) { return x; } unsigned f(unsigned x) { return cp(x * 2) * 2 + cp(cp(x * 2) * 3) * 5; } $ cat ./test1.c.085t.phiopt2 ;; Function f (f, funcdef_no=1, decl_uid=1393, symbol_order=1) f (unsigned int x) { unsigned int _2; unsigned int _3; unsigned int _4; unsigned int _5; unsigned int _6; : _2 = x_1(D) * 2; _5 = 15; _3 = _5 + 2; _4 = _2 * _3; _6 = _4; return _6; } $ cat ./test1.c.087t.ccp3 ;; Function f (f, funcdef_no=1, decl_uid=1393, symbol_order=1) Pass statistics: ---------------- Immediate_uses: x_1(D) : --> single use. _2 = x_1(D) * 2; _2 : --> single use. _4 = _2 * _3; _3 : --> single use. _4 = _2 * _3; _4 : --> single use. _6 = _4; _5 : --> single use. _3 = _5 + 2; _6 : --> single use. return _6; .MEM_7(D) : --> single use. # VUSE <.MEM_7(D)> return _6; Adding Destination of edge (0 -> 2) to worklist Simulating block 2 Visiting statement: # RANGE [0, 4294967295] NONZERO 0x000000000fffffffe _2 = x_1(D) * 2; which is likely CONSTANT Lattice value changed to CONSTANT 0x00000000000000000 (0x000000000fffffffe). Adding SSA edges to worklist. Visiting statement: # RANGE [0, 4294967295] NONZERO 0x000000000fffffffe _5 = 15; which is likely CONSTANT Lattice value changed to CONSTANT 14. Adding SSA edges to worklist. Visiting statement: _3 = _5 + 2; which is likely CONSTANT Lattice value changed to CONSTANT 16. Adding SSA edges to worklist. Visiting statement: _4 = _2 * _3; which is likely CONSTANT Lattice value changed to CONSTANT 0x00000000000000000 (0x000000000ffffffe0). Adding SSA edges to worklist. Visiting statement: # RANGE [0, 4294967295] NONZERO 0x000000000fffffffe _6 = _4; Lattice value changed to CONSTANT 0x00000000000000000 (0x000000000ffffffe0). Adding SSA edges to worklist. Visiting statement: # VUSE <.MEM_7(D)> return _6; No interesting values produced. Marked VARYING. Substituting values and folding statements Folding statement: return _6; Not folded Folding statement: _6 = _4; Not folded Folding statement: _4 = _2 * _3; Folded into: _4 = _2 * 16; Removing dead stmt _3 = 16; Removing dead stmt _5 = 14; Folding statement: _2 = x_1(D) * 2; Not folded Pass statistics: ---------------- Constants propagated: 1 Statements deleted: 2 f (unsigned intD.4 xD.1392) { unsigned intD.4 _2; unsigned intD.4 _4; unsigned intD.4 _6; ;; basic block 2, loop depth 0, count 0, freq 10000, maybe hot ;; prev block 0, next block 1, flags: (NEW, REACHABLE) ;; pred: ENTRY [100.0%] (FALLTHRU,EXECUTABLE) # RANGE [0, 4294967295] NONZERO 0x000000000fffffffe _2 = x_1(D) * 2; # RANGE [0, 4294967295] NONZERO 0x000000000ffffffe0 _4 = _2 * 16; # RANGE [0, 4294967295] NONZERO 0x000000000ffffffe0 _6 = _4; # VUSE <.MEM_7(D)> return _6; ;; succ: EXIT [100.0%] }