From patchwork Tue Jan 18 22:54:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 79371 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 E8EB7B711B for ; Wed, 19 Jan 2011 09:55:10 +1100 (EST) Received: (qmail 29609 invoked by alias); 18 Jan 2011 22:55:08 -0000 Received: (qmail 29599 invoked by uid 22791); 18 Jan 2011 22:55:08 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_FN, 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; Tue, 18 Jan 2011 22:55:01 +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.13.8/8.13.8) with ESMTP id p0IMt0g4022464 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 18 Jan 2011 17:55:00 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p0IMsxLi011357 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 18 Jan 2011 17:54:59 -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 p0IMswOb029506 for ; Tue, 18 Jan 2011 23:54:59 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p0IMsw5o029505 for gcc-patches@gcc.gnu.org; Tue, 18 Jan 2011 23:54:58 +0100 Date: Tue, 18 Jan 2011 23:54:58 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix find_call_stack_args in RTL DCE (PR rtl-optimization/47337) Message-ID: <20110118225458.GK2724@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! I've made a thinko in this routine, the break; out of the for loop iterating over each byte in the MEM was meant to break out of the outer loop, but only terminated the inner loop, thus if some unrelated sp related memory store was moved after some stack argument store, RTL DCE would happily delete it together with the call if it is being DCEd. Fixed thusly. Also I've fixed a potential -fcompare-debug issue, DEBUG_INSNs should be ignored here rather than make the call non-DCEable. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-01-18 Jakub Jelinek PR rtl-optimization/47337 * dce.c (find_call_stack_args): Ignore debug insns. Stop on memory stores other than argument stores. * gcc.c-torture/execute/pr47337.c: New test. Jakub --- gcc/dce.c.jj 2011-01-03 19:22:53.000000000 +0100 +++ gcc/dce.c 2011-01-18 10:37:12.590320188 +0100 @@ -374,7 +374,7 @@ find_call_stack_args (rtx call_insn, boo if (CALL_P (insn)) break; - if (!INSN_P (insn)) + if (!NONDEBUG_INSN_P (insn)) continue; set = single_set (insn); @@ -444,6 +444,9 @@ find_call_stack_args (rtx call_insn, boo break; } + if (byte < off + GET_MODE_SIZE (GET_MODE (mem))) + break; + if (!deletable_insn_p (insn, fast, NULL)) break; --- gcc/testsuite/gcc.c-torture/execute/pr47337.c.jj 2011-01-18 10:51:43.539389291 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr47337.c 2011-01-18 10:51:16.000000000 +0100 @@ -0,0 +1,86 @@ +/* PR rtl-optimization/47337 */ + +static unsigned int a[256], b = 0; +static char c = 0; +static int d = 0, *f = &d; +static long long e = 0; + +static short +foo (long long x, long long y) +{ + return x / y; +} + +static char +bar (char x, char y) +{ + return x - y; +} + +static int +baz (int x, int y) +{ + *f = (y != (short) (y * 3)); + for (c = 0; c < 2; c++) + { + lab: + if (d) + { + if (e) + e = 1; + else + return x; + } + else + { + d = 1; + goto lab; + } + f = &d; + } + return x; +} + +static void +fnx (unsigned long long x, int y) +{ + if (!y) + { + b = a[b & 1]; + b = a[b & 1]; + b = a[(b ^ (x & 1)) & 1]; + b = a[(b ^ (x & 1)) & 1]; + } +} + +char *volatile w = "2"; + +int +main () +{ + int h = 0; + unsigned int k = 0; + int l[8]; + int i, j; + + if (__builtin_strcmp (w, "1") == 0) + h = 1; + + for (i = 0; i < 256; i++) + { + for (j = 8; j > 0; j--) + k = 1; + a[i] = k; + } + for (i = 0; i < 8; i++) + l[i] = 0; + + d = bar (c, c); + d = baz (c, 1 | foo (l[0], 10)); + fnx (d, h); + fnx (e, h); + + if (d != 0) + __builtin_abort (); + return 0; +}