From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15705 invoked by alias); 14 Oct 2013 20:04:31 -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 15679 invoked by uid 48); 14 Oct 2013 20:04:28 -0000 From: "congh at google dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/58728] New: [missed optimization] == or != comparisons may affect range test optimization. Date: Mon, 14 Oct 2013 20:04:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: congh at google dot com X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: 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: 2013-10/txt/msg00829.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58728 Bug ID: 58728 Summary: [missed optimization] == or != comparisons may affect range test optimization. Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: congh at google dot com Created attachment 31002 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31002&action=edit Patch Look at the following code: int foo(unsigned int n) { if (n != 0) if (n != 1) if (n != 2) if (n != 3) if (n != 4) return ++n; return n; } Those five comparisons should be able to be merged into one during range test optimization but they are not. The reason is that GCC checks the phi args of n after the branch to make sure two false edges of two neighboring ifs define the same phi arg at the join node (thus guarantees side-effect free). However, the "vrp" pass replaced the phi arg by the identical value of the original phi arg deducted from == or != comparisons, hence preventing the range test optimization. The same case is in if-combine pass. I made a patch for this issue which is attached here.