From patchwork Mon Jan 23 05:33:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 137261 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 2919FB6FA0 for ; Mon, 23 Jan 2012 16:34:09 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1327901650; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=ijrBaX0 3YKY7UKuEa3rgtmXyTy0=; b=xVzf0cTdcTTmo0+rmjbKF9jgA8SKB2C6mg1Kuh6 dBxbgkQOGyvgVMEnqbgx8uL8Adhp0me0Ioe38rTm5NuF6UH4hdacVoW9+AOmMvgz NXT6os6wAanRt4dshzW3XOnkX+Tg8zYNlrpstVfMfQdy9nMOiLP1sj+bia/DEoNE IFtI= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Z2Km7O3ogR3D4xSs7skONKxndE6EB3DXJkUcApekQ9kabBaMVgWVhIidKKZNrE T1U8IZUHdQEpr6RSw+W0+GY0X/sZP9iHI56XhNU4VdpW4xv085oT1heSvgiHTthN SsE7lx8ByE653zyIHAnlxiDRg4brUY56ilzJ6vdrR9qlo=; Received: (qmail 30740 invoked by alias); 23 Jan 2012 05:34:05 -0000 Received: (qmail 30388 invoked by uid 22791); 23 Jan 2012 05:34:03 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-ww0-f51.google.com (HELO mail-ww0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 Jan 2012 05:33:45 +0000 Received: by wgbdy1 with SMTP id dy1so2179552wgb.8 for ; Sun, 22 Jan 2012 21:33:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.180.86.105 with SMTP id o9mr4108195wiz.4.1327296824192; Sun, 22 Jan 2012 21:33:44 -0800 (PST) Received: by 10.216.12.209 with HTTP; Sun, 22 Jan 2012 21:33:44 -0800 (PST) Date: Sun, 22 Jan 2012 21:33:44 -0800 Message-ID: Subject: [PATCH] Fix PR 29333: Jump threading getting in the way of PHI-OPT From: Andrew Pinski To: GCC Patches X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, The problem here is not really jump threading getting in the way of PHI-OPT rather there is no cleanup of the IR after jump thread but before phi-opt. This patch adds a pass_phi_only_cprop right after the first vrp and pass_merge_phi right before the first and last phiopts. Since VRP does jump threading just like DOM does, we need a pass_phi_only_cprop right after it. And the merge PHI pass should be done so that going into PHI-OPT we have a CFG which there is only one PHI for a case like: bb0: if (a) goto L1; bb3: if (b) goto L2; L1: x = PHI L2: x= PHI PHI-OPT does not handle PHIs like this that well. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Thanks, Andrew Pinski ChangeLog: * passes.c (init_optimization_passes): Add pass_phi_only_cprop after the first vpr pass. Add pass_merge_phi before the first and last phiopt passes. testsuite/ChangeLog: * gcc.dg/tree-ssa/phi-opt-7.c: New testcase. Index: testsuite/gcc.dg/tree-ssa/phi-opt-7.c =================================================================== --- testsuite/gcc.dg/tree-ssa/phi-opt-7.c (revision 0) +++ testsuite/gcc.dg/tree-ssa/phi-opt-7.c (revision 0) @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-phiopt1" } */ + + +int minmax_correct(int a) +{ + if (a > 32767) a = 32767; + else if (a < -32768) a = -32768; + + return a; +} + +int minmax_wrong(int a) +{ + if (a > 32767) a = 32767; + if (a < -32768) a = -32768; + + return a; +} + +/* { dg-final { scan-tree-dump-not "if" "phiopt1" } } */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "phiopt1" } } */ +/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "phiopt1" } } */ +/* { dg-final { cleanup-tree-dump "phiopt1" } } */ + Index: passes.c =================================================================== --- passes.c (revision 183396) +++ passes.c (working copy) @@ -1302,9 +1302,11 @@ init_optimization_passes (void) NEXT_PASS (pass_copy_prop); NEXT_PASS (pass_merge_phi); NEXT_PASS (pass_vrp); + NEXT_PASS (pass_phi_only_cprop); NEXT_PASS (pass_dce); NEXT_PASS (pass_cselim); NEXT_PASS (pass_tree_ifcombine); + NEXT_PASS (pass_merge_phi); NEXT_PASS (pass_phiopt); NEXT_PASS (pass_tail_recursion); NEXT_PASS (pass_ch); @@ -1401,6 +1403,7 @@ init_optimization_passes (void) NEXT_PASS (pass_late_warn_uninitialized); NEXT_PASS (pass_dse); NEXT_PASS (pass_forwprop); + NEXT_PASS (pass_merge_phi); NEXT_PASS (pass_phiopt); NEXT_PASS (pass_fold_builtins); NEXT_PASS (pass_optimize_widening_mul);