From patchwork Mon Feb 6 20:43:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 139791 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 E7FDE1007D1 for ; Tue, 7 Feb 2012 07:44:08 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1329165850; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=FyO+RHG0WEgyizTfVnX4 Y776yjQ=; b=Jhn+WX0DQ+PwXSZ+VgOjvihOl15X5egoDe0zOrziQeeV+KgnStLM gNmOYeS3ZBQnqrRZkO3L4LDzwF81Bm+rK23tlatIz42fK3F54fzh0/Ox72sG4lZl HQsWUN8+AWAANtQDfcqMN31ELpCzSuxCaIe6WdV2IAgi8+w1hKDFpkY= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=iAy340oTqYtxPEN9lMHnvuBbOHTNVR5OdqwqHFdxwMki7s7RrX0O8rWbyNkPxK cJOtK4rHJ2tetwh/MYij7oSJXk43FFf9F6Aw9OmL2323317/i5F/49hqmQzXC636 jimnCMckvQSBIqI7MudqPHXQ7ygDebjTXXhThchznVHTI=; Received: (qmail 7881 invoked by alias); 6 Feb 2012 20:44:05 -0000 Received: (qmail 7870 invoked by uid 22791); 6 Feb 2012 20:44:04 -0000 X-SWARE-Spam-Status: No, hits=-6.7 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; Mon, 06 Feb 2012 20:43:45 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q16KhMsG004492 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 6 Feb 2012 15:43:23 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q16KhLIb028897 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 6 Feb 2012 15:43:22 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id q16KhKK1008712; Mon, 6 Feb 2012 21:43:20 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id q16KhJr4008711; Mon, 6 Feb 2012 21:43:19 +0100 Date: Mon, 6 Feb 2012 21:43:19 +0100 From: Jakub Jelinek To: Eric Botcazou , Richard Sandiford Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix combiner with added_sets_[12] (PR rtl-optimization/52060) Message-ID: <20120206204319.GT18768@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! combine_simplify_rtx and its helpers (called from subst) apparently modify the given RTL in-place, there are many SUBST () calls all around those functions. On the attached testcase in particular on arm when newpat = subst (newpat, i1dest, i1src, 0, 0, 0); is called, force_to_mode modifies the if_then_else operands through SUBST, which modifies i1src. When I2 dest is needed later on (i.e. added_sets_2), we subst this i1src unintentionally clobbered into i2pat, which is incorrect, as that transformation was only valid as part of the i3 pattern. Fixed by making a copy of i1src and i0src before we pass those as to argument to subst, if we'll need them later on for added_sets_[01]. Bootstrapped/regtested on x86_64-linux and i686-linux, tested with cross to arm, ok for trunk? 2012-02-06 Jakub Jelinek PR rtl-optimization/52060 * combine.c (try_combine): Add i0src_copy and i0src_copy2 variables, copy i1src to i1src_copy whenever added_sets_2 && i1_feeds_i2_n already before i1dest -> i1src substitution in newpat, copy i0src to i0src_copy and/or i0src_copy2 when needed. * gcc.dg/torture/pr52060.c: New test. Jakub --- gcc/combine.c.jj 2012-02-03 13:31:41.000000000 +0100 +++ gcc/combine.c 2012-02-06 17:49:40.000000000 +0100 @@ -2591,8 +2591,8 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx rtx i3dest_killed = 0; /* SET_DEST and SET_SRC of I2, I1 and I0. */ rtx i2dest = 0, i2src = 0, i1dest = 0, i1src = 0, i0dest = 0, i0src = 0; - /* Copy of SET_SRC of I1, if needed. */ - rtx i1src_copy = 0; + /* Copy of SET_SRC of I1 and I0, if needed. */ + rtx i1src_copy = 0, i0src_copy = 0, i0src_copy2 = 0; /* Set if I2DEST was reused as a scratch register. */ bool i2scratch = false; /* The PATTERNs of I0, I1, and I2, or a copy of them in certain cases. */ @@ -3246,6 +3246,11 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx n_occurrences = 0; subst_low_luid = DF_INSN_LUID (i1); + /* If the following substitution will modify I1SRC, make a copy of it + for the case where it is substituted for I1DEST in I2PAT later. */ + if (added_sets_2 && i1_feeds_i2_n) + i1src_copy = copy_rtx (i1src); + /* If I0 feeds into I1 and I0DEST is in I0SRC, we need to make a unique copy of I1SRC each time we substitute it, in order to avoid creating self-referential RTL when we will be substituting I0SRC for I0DEST @@ -3273,10 +3278,14 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx return 0; } - /* If the following substitution will modify I1SRC, make a copy of it - for the case where it is substituted for I1DEST in I2PAT later. */ - if (i0_feeds_i1_n && added_sets_2 && i1_feeds_i2_n) - i1src_copy = copy_rtx (i1src); + /* If the following substitution will modify I0SRC, make a copy of it + for the case where it is substituted for I0DEST in I1PAT later. */ + if (added_sets_1 && i0_feeds_i1_n) + i0src_copy = copy_rtx (i0src); + /* And a copy for I0DEST in I2PAT substitution. */ + if (added_sets_2 && ((i0_feeds_i1_n && i1_feeds_i2_n) + || (i0_feeds_i2_n))) + i0src_copy2 = copy_rtx (i0src); n_occurrences = 0; subst_low_luid = DF_INSN_LUID (i0); @@ -3342,7 +3351,7 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx { rtx t = i1pat; if (i0_feeds_i1_n) - t = subst (t, i0dest, i0src, 0, 0, 0); + t = subst (t, i0dest, i0src_copy ? i0src_copy : i0src, 0, 0, 0); XVECEXP (newpat, 0, --total_sets) = t; } @@ -3353,7 +3362,7 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx t = subst (t, i1dest, i1src_copy ? i1src_copy : i1src, 0, 0, i0_feeds_i1_n && i0dest_in_i0src); if ((i0_feeds_i1_n && i1_feeds_i2_n) || i0_feeds_i2_n) - t = subst (t, i0dest, i0src, 0, 0, 0); + t = subst (t, i0dest, i0src_copy2 ? i0src_copy2 : i0src, 0, 0, 0); XVECEXP (newpat, 0, --total_sets) = t; } --- gcc/testsuite/gcc.dg/torture/pr52060.c.jj 2012-02-06 18:35:51.215511107 +0100 +++ gcc/testsuite/gcc.dg/torture/pr52060.c 2012-02-06 18:34:18.000000000 +0100 @@ -0,0 +1,57 @@ +/* PR rtl-optimization/52060 */ +/* { dg-do run { target int32plus } } */ + +extern void abort (void); +union U { float f; unsigned int i; }; + +static inline __attribute__((always_inline)) unsigned int +foo (float x) +{ + union U u; + unsigned int a, b, c; + int d; + int e; + u.f = x; + d = ((unsigned) u.i >> 23) & 0xFF; + c = d < 126 ? 0 : ~0; + e = 127 + 30 - d; + a = (u.i << 8) | 0x80000000U; + b = a & ((1 << e) - 1); + a = a >> e; + c &= (b | (a & 2)) ? ~0 : ~1; + a = ((a + 1U) >> 1) & c; + return a; +} + +__attribute__((noinline)) unsigned int +bar (float x) +{ + unsigned int a, b, c; + static const unsigned int d[128] = + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7 + }; + a = foo (1048575.0f * x); + c = d[a >> 13]; + b = (c << 13) | ((a >> (7 - c)) & 0x1fff); + return b; +} + +int +main () +{ + union U u; + u.f = 1048575.0f; + if (sizeof (u.i) == sizeof (u.f) + && u.i == 0x497ffff0U + && bar (1.0f) != 65535) + abort (); + return 0; +}