From patchwork Wed Jul 28 16:13:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Kuvyrkov X-Patchwork-Id: 60161 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 E4203B6F01 for ; Thu, 29 Jul 2010 02:14:15 +1000 (EST) Received: (qmail 26533 invoked by alias); 28 Jul 2010 16:14:12 -0000 Received: (qmail 26522 invoked by uid 22791); 28 Jul 2010 16:14:10 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 28 Jul 2010 16:14:02 +0000 Received: (qmail 6620 invoked from network); 28 Jul 2010 16:14:00 -0000 Received: from unknown (HELO ?172.16.1.24?) (maxim@127.0.0.2) by mail.codesourcery.com with ESMTPA; 28 Jul 2010 16:14:00 -0000 Message-ID: <4C505746.5010707@codesourcery.com> Date: Wed, 28 Jul 2010 20:13:58 +0400 From: Maxim Kuvyrkov User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.7) Gecko/20100713 Thunderbird/3.1.1 MIME-Version: 1.0 To: gcc-patches CC: Jeff Law Subject: [PATCH] Fix bug in hoisting when using -fgcse-las 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 This patch fixes http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45107 . The problem is due to mismatch in max_distance values for the same expression when it is processed on the LHS versus the RHS. More specifically, the problem due to me not including -fgcse-las in the testing of hoisting improvements patches. The attached patch fixes the bug. It was tested by bootstrapping GCC with -fgcse-las in BOOT_CFLAGS. OK to apply? diff --git a/gcc/gcse.c b/gcc/gcse.c index 1124131..6e923f9 100644 --- a/gcc/gcse.c +++ b/gcc/gcse.c @@ -1471,6 +1471,7 @@ hash_scan_set (rtx pat, rtx insn, struct hash_table_d *table) else if (flag_gcse_las && REG_P (src) && MEM_P (dest)) { unsigned int regno = REGNO (src); + int max_distance = 0; /* Do not do this for constant/copy propagation. */ if (! table->set_p @@ -1482,7 +1483,7 @@ hash_scan_set (rtx pat, rtx insn, struct hash_table_d *table) do that easily for EH edges so disable GCSE on these for now. */ && !can_throw_internal (insn) /* Is SET_DEST something we want to gcse? */ - && want_to_gcse_p (dest, NULL) + && want_to_gcse_p (dest, &max_distance) /* Don't CSE a nop. */ && ! set_noop_p (pat) /* Don't GCSE if it has attached REG_EQUIV note. @@ -1504,7 +1505,7 @@ hash_scan_set (rtx pat, rtx insn, struct hash_table_d *table) /* Record the memory expression (DEST) in the hash table. */ insert_expr_in_table (dest, GET_MODE (dest), insn, - antic_p, avail_p, 0, table); + antic_p, avail_p, max_distance, table); } } } diff --git a/gcc/testsuite/gcc.dg/pr45107.c b/gcc/testsuite/gcc.dg/pr45107.c new file mode 100644 index 0000000..05dbec3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr45107.c @@ -0,0 +1,13 @@ +/* PR rtl-optimization/45107 */ +/* { dg-do compile } */ +/* { dg-options "-Os -fgcse-las" } */ + +extern void bar(int *); + +int foo (int *p) +{ + int i = *p; + if (i != 1) + bar(&i); + *p = i; +}