From patchwork Thu Jan 6 12:10:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 77705 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 3A838B713A for ; Thu, 6 Jan 2011 23:10:19 +1100 (EST) Received: (qmail 11001 invoked by alias); 6 Jan 2011 12:10:15 -0000 Received: (qmail 10946 invoked by uid 22791); 6 Jan 2011 12:10:13 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 06 Jan 2011 12:10:07 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p06CA6W9000456 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 6 Jan 2011 07:10:06 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p06CA5Sd010610 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 6 Jan 2011 07:10:05 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p06CA4DZ024441 for ; Thu, 6 Jan 2011 13:10:04 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p06CA3X7023675 for gcc-patches@gcc.gnu.org; Thu, 6 Jan 2011 13:10:03 +0100 Date: Thu, 6 Jan 2011 13:10:03 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix stringop profile feedback optimization (PR bootstrap/47187) Message-ID: <20110106121003.GS16156@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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! If a memcpy/mempcpy/memset has lhs and profile feedback estimates some likely size, the GIMPLE is invalid, because both calls use the same SSA_NAME on the lhs. Fixed thusly, bootstrapped/regtested on i686-linux (x86_64-linux regtest pending), ok for trunk? 2011-01-06 Jakub Jelinek PR bootstrap/47187 * value-prof.c (gimple_stringop_fixed_value): Handle lhs of the call properly. * gcc.dg/tree-prof/pr47187.c: New test. Jakub --- gcc/value-prof.c.jj 2010-12-22 09:54:58.000000000 +0100 +++ gcc/value-prof.c 2011-01-06 11:12:39.000000000 +0100 @@ -1401,6 +1401,21 @@ gimple_stringop_fixed_value (gimple vcal e_vj->probability = REG_BR_PROB_BASE; e_vj->count = all - count; + /* Insert PHI node for the call result if necessary. */ + if (gimple_call_lhs (vcall_stmt) + && TREE_CODE (gimple_call_lhs (vcall_stmt)) == SSA_NAME) + { + tree result = gimple_call_lhs (vcall_stmt); + gimple phi = create_phi_node (result, join_bb); + SSA_NAME_DEF_STMT (result) = phi; + gimple_call_set_lhs (vcall_stmt, + make_ssa_name (SSA_NAME_VAR (result), vcall_stmt)); + add_phi_arg (phi, gimple_call_lhs (vcall_stmt), e_vj, UNKNOWN_LOCATION); + gimple_call_set_lhs (icall_stmt, + make_ssa_name (SSA_NAME_VAR (result), icall_stmt)); + add_phi_arg (phi, gimple_call_lhs (icall_stmt), e_ij, UNKNOWN_LOCATION); + } + /* Because these are all string op builtins, they're all nothrow. */ gcc_assert (!stmt_could_throw_p (vcall_stmt)); gcc_assert (!stmt_could_throw_p (icall_stmt)); --- gcc/testsuite/gcc.dg/tree-prof/pr47187.c.jj 2011-01-06 11:23:10.000000000 +0100 +++ gcc/testsuite/gcc.dg/tree-prof/pr47187.c 2011-01-06 11:20:14.000000000 +0100 @@ -0,0 +1,23 @@ +/* PR bootstrap/47187 */ +/* { dg-options "-O2" } */ + +char buf[64]; +char buf2[64]; + +void * +foo (char *p, long size) +{ + return __builtin_memcpy (buf, p, size); +} + +int +main (void) +{ + long i; + for (i = 0; i < 65536; i++) + if (foo ("abcdefghijkl", 12) != buf) + __builtin_abort (); + if (foo (buf2, 64) != buf) + __builtin_abort (); + return 0; +}