From patchwork Sat May 10 22:53:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 347739 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AA68014008A for ; Sun, 11 May 2014 08:53:59 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=Nx2jGeQ5VNahJBmsf+XyygLT7cM0UORcGRqu0Pdn7Pl7fF1aqCwZ6 DsHbf2Eum7kiHNqaUY7KbMHVDRHaKobaSmmPX8/ybN/iaL7/GvsRGbYUm4+M/JOc x2ze8GzgAGQVxGOKlJIVKmydE3s/1N0DaJdVAmB8cUz+z13+7DfMZs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=//QtrhonZcY652PE8kCn6bqdf7Y=; b=ISdB+2Ow2IoDRTl733M0 g+UFMhSDCcckjXtNxXVRgyY/zNbdQ8KZTqK4PKsgN0HlRLSUGJjJBH9o14W5TAOC F2x5hcl4h6kXenVcUFHr8QjhjT9n6KfXfIjpQUTyaqI+epLyfvwtfSM7IN16dHI8 PGdup1E3IMnNzVsbwAw9awE= Received: (qmail 12186 invoked by alias); 10 May 2014 22:53:52 -0000 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 Received: (qmail 12175 invoked by uid 89); 10 May 2014 22:53:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail3-relais-sop.national.inria.fr Received: from mail3-relais-sop.national.inria.fr (HELO mail3-relais-sop.national.inria.fr) (192.134.164.104) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Sat, 10 May 2014 22:53:50 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/AES128-SHA; 11 May 2014 00:53:46 +0200 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.82) (envelope-from ) id 1WjG9K-0003Bl-EF for gcc-patches@gcc.gnu.org; Sun, 11 May 2014 00:53:46 +0200 Date: Sun, 11 May 2014 00:53:46 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: PR61140: check the phi is unique in value_replacement Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Hello, in my recent phiopt patch enhancing value_replacement to optimize x!=0?x+y:y, I forgot to check that there is no other PHI (not sure how I managed to miss that since I copy-pasted the line just below the test). If there are other phi nodes (with different arguments for those 2 branches), it would be possible to replace the phi argument and stop there (as value_replacement does for its other transformation). However, I am chosing to punt. The cost analysis would be different, and I wrote the transformation assuming that this single-phi test was already done higher in the function. Bootstrap+testsuite on x86_64-linux-gnu. 2014-05-12 Marc Glisse PR tree-optimization/61140 gcc/ * tree-ssa-phiopt.c (value_replacement): Punt on multiple phis. gcc/testsuite/ * gcc.dg/tree-ssa/pr61140.c: New file. Index: gcc/testsuite/gcc.dg/tree-ssa/pr61140.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/pr61140.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/pr61140.c (working copy) @@ -0,0 +1,18 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +int a[1] = { 1 }, b = 1, c; + +int +main () +{ + for (; c < 1; c++) + if (a[0]) + { + a[0] &= 1; + b = 0; + } + if (b) + __builtin_abort (); + return 0; +} Index: gcc/tree-ssa-phiopt.c =================================================================== --- gcc/tree-ssa-phiopt.c (revision 210301) +++ gcc/tree-ssa-phiopt.c (working copy) @@ -842,20 +842,24 @@ value_replacement (basic_block cond_bb, /* Now optimize (x != 0) ? x + y : y to just y. The following condition is too restrictive, there can easily be another stmt in middle_bb, for instance a CONVERT_EXPR for the second argument. */ gimple assign = last_and_only_stmt (middle_bb); if (!assign || gimple_code (assign) != GIMPLE_ASSIGN || gimple_assign_rhs_class (assign) != GIMPLE_BINARY_RHS || (!INTEGRAL_TYPE_P (TREE_TYPE (arg0)) && !POINTER_TYPE_P (TREE_TYPE (arg0)))) return 0; + /* Only transform if it removes the condition. */ + if (!single_non_singleton_phi_for_edges (phi_nodes (gimple_bb (phi)), e0, e1)) + return 0; + /* Size-wise, this is always profitable. */ if (optimize_bb_for_speed_p (cond_bb) /* The special case is useless if it has a low probability. */ && profile_status_for_fn (cfun) != PROFILE_ABSENT && EDGE_PRED (middle_bb, 0)->probability < PROB_EVEN /* If assign is cheap, there is no point avoiding it. */ && estimate_num_insns (assign, &eni_time_weights) >= 3 * estimate_num_insns (cond, &eni_time_weights)) return 0;