From patchwork Fri Jan 10 21:36:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 309422 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 D71182C0089 for ; Sat, 11 Jan 2014 08:36:58 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=jv2bsDSbHnZKiPZmjR7BQ3Sm7iQsi9LgxKOdg38J9sT1sj 5ZCjtt1Vg+NJicyhHlr9jztJ6Hl+Lzzk+LdpS/RSSMWtKItnRNzaycaXV7ZYusjU 04MXnyOIoSWiKAFgvJ/YT6KzUJ32/khQbeZQbB0/qdqofFHd7qBN9pEL79FrQ= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=/P98e09sPYsZvmVNkc4eMqS3u/c=; b=rtMEO1wnJNKE0mbU5E98 9iPKrbZSHxOGG8esI7MkETvFRUXnMQ3No7p6qGwNhduc48VeUAVAPzXICZejwPKX K79ebs4BysyE4ie9K2LUXdG+1wuIiCsw+FWzc5Gcfh14kpNPRnilaBN0DUH3qIV0 6u/wOhh9r3LDuAUhcjbWI9s= Received: (qmail 18244 invoked by alias); 10 Jan 2014 21:36:51 -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 18232 invoked by uid 89); 10 Jan 2014 21:36:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Jan 2014 21:36:49 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0ALamiO016960 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 10 Jan 2014 16:36:48 -0500 Received: from stumpy.slc.redhat.com (ovpn-113-36.phx2.redhat.com [10.3.113.36]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s0ALal9L016067 for ; Fri, 10 Jan 2014 16:36:48 -0500 Message-ID: <52D067EF.7020005@redhat.com> Date: Fri, 10 Jan 2014 14:36:47 -0700 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: gcc-patches Subject: [RFA] [PATCH][PR tree-optimization/59749] Fix recently introduced ree bug X-IsSubscribed: yes As mentioned in the PR. We have a memory load and two extensions. The first extension requires a copy because its source and destination are not the same hard register. The second extension does not require a copy and has a wider mode than the first extension. In this case we have to make sure to widen the copy we emit to eliminate the first extension. Otherwise upper bits aren't going to have their expected values. Thankfully the copy isn't emitted until the end of ree and we have the modified memory reference to peek at to get the proper mode. Bootstrapped and regression tested on x86_64-unknown-linux-gnu. OK for the trunk? commit 7a83f984205b101f61dbfcabef59e8f459950f88 Author: Jeff Law Date: Fri Jan 10 14:31:15 2014 -0700 PR tree-optimization/59747 * ree.c (find_and_remove_re): Properly handle case where a second eliminated extension requires widening a copy created for elimination of a prior extension. PR tree-optimization/59747 * gcc.c-torture/execute/pr59747.c: New test. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a125517..4294831 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2014-01-10 Jeff Law + + PR tree-optimization/59747 + * ree.c (find_and_remove_re): Properly handle case where a second + eliminated extension requires widening a copy created for elimination + of a prior extension. + 2014-01-09 Rong Xu * libgcc/libgcov-driver.c (this_prg): make it local to save diff --git a/gcc/ree.c b/gcc/ree.c index 1c4f3ad..0a34131 100644 --- a/gcc/ree.c +++ b/gcc/ree.c @@ -1003,11 +1003,20 @@ find_and_remove_re (void) for (unsigned int i = 0; i < reinsn_copy_list.length (); i += 2) { rtx curr_insn = reinsn_copy_list[i]; + rtx def_insn = reinsn_copy_list[i + 1]; + + /* Use the mode of the destination of the defining insn + for the mode of the copy. This is necessary if the + defining insn was used to eliminate a second extension + that was wider than the first. */ + rtx sub_rtx = *get_sub_rtx (def_insn); rtx pat = PATTERN (curr_insn); - rtx new_reg = gen_rtx_REG (GET_MODE (SET_DEST (pat)), + rtx new_dst = gen_rtx_REG (GET_MODE (SET_DEST (sub_rtx)), REGNO (XEXP (SET_SRC (pat), 0))); - rtx set = gen_rtx_SET (VOIDmode, new_reg, SET_DEST (pat)); - emit_insn_after (set, reinsn_copy_list[i + 1]); + rtx new_src = gen_rtx_REG (GET_MODE (SET_DEST (sub_rtx)), + REGNO (SET_DEST (pat))); + rtx set = gen_rtx_SET (VOIDmode, new_dst, new_src); + emit_insn_after (set, def_insn); } /* Delete all useless extensions here in one sweep. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index acb1637..1023133 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-01-10 Jeff Law + + PR tree-optimization/59747 + * gcc.c-torture/execute/pr59747.c: New test. + 2014-10-09 Jakub Jelinek PR sanitizer/59136 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr59747.c b/gcc/testsuite/gcc.c-torture/execute/pr59747.c new file mode 100644 index 0000000..edb1685 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr59747.c @@ -0,0 +1,28 @@ +extern void abort (void) __attribute__ ((__noreturn__)); +extern void exit (int) __attribute__ ((__noreturn__)); +extern int printf (const char *, ...); + +int a[6], b, c = 1, d; +short e; + +int __attribute__ ((noinline)) +fn1 (int p) +{ + b = a[p]; +} + +int +main () +{ + if (sizeof (long long) != 8) + exit (0); + + a[0] = 1; + if (c) + e--; + d = e; + long long f = e; + if (fn1 ((f >> 56) & 1) != 0) + abort (); + exit (0); +}