From patchwork Mon May 9 19:11:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 94918 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 06100B6F0C for ; Tue, 10 May 2011 09:12:24 +1000 (EST) Received: (qmail 21656 invoked by alias); 9 May 2011 19:12:22 -0000 Received: (qmail 21646 invoked by uid 22791); 9 May 2011 19:12:20 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_DF, 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, 09 May 2011 19:12:02 +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.14.4/8.14.4) with ESMTP id p49JC2LT030912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 9 May 2011 15:12:02 -0400 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 p49JC1cc028944 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 9 May 2011 15:12:01 -0400 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 p49JC0OO015966; Mon, 9 May 2011 21:12:00 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p49JC0m3015964; Mon, 9 May 2011 21:12:00 +0200 Date: Mon, 9 May 2011 21:11:59 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Cc: Ben Elliston Subject: [PATCH] Fix dfp issue with dconst{1,2,m1,half} (PR debug/48928) Message-ID: <20110509191159.GX17079@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! The folder/middle-end/tree passes/rtl passes apparently use dconst{1,2,m1,half} and/or const_tiny_rtx[{1,2}][{S,D,T}Dmode] in various places. E.g. /* Convert x+x into x*2.0. */ if (operand_equal_p (arg0, arg1, 0) && SCALAR_FLOAT_TYPE_P (type)) return fold_build2_loc (loc, MULT_EXPR, type, arg0, build_real (type, dconst2)); Unfortunately, dconst{1,2,m1,half} are binary REAL_FORMATs, not decimal. In most places real.c or dfp.c just converts constants to decimal, but when doing decimal_to_decnumber on such constants it fails with an assertion failure. While we perhaps could add code to handle decimal stuff in all places where dconst{1,2,m1,half} is mentioned, say create dconstdfp{1,2,m1,half}, I think it would just make all the code harder to maintain, so instead of that this patch just magically converts those binary tiny predefined constants to decimal. Instead of calling decimal_from_binary which converts it to string and then from string back to dn the patch just converts strings to dn. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-05-09 Jakub Jelinek PR debug/48928 * dfp.c (decimal_to_decnumber): Handle conversion from dconst{1,2,m1,half}. * gcc.dg/dfp/pr48928.c: New test. Jakub --- gcc/dfp.c.jj 2010-12-02 11:51:32.000000000 +0100 +++ gcc/dfp.c 2011-05-09 11:08:43.000000000 +0200 @@ -110,7 +110,33 @@ decimal_to_decnumber (const REAL_VALUE_T decNumberFromString (dn, "nan", &set); break; case rvc_normal: - gcc_assert (r->decimal); + if (!r->decimal) + { + /* dconst{1,2,m1,half} are used in various places in + the middle-end and optimizers, allow them here + as an exception by converting them to decimal. */ + if (memcmp (r, &dconst1, sizeof (*r)) == 0) + { + decNumberFromString (dn, "1", &set); + break; + } + if (memcmp (r, &dconst2, sizeof (*r)) == 0) + { + decNumberFromString (dn, "2", &set); + break; + } + if (memcmp (r, &dconstm1, sizeof (*r)) == 0) + { + decNumberFromString (dn, "-1", &set); + break; + } + if (memcmp (r, &dconsthalf, sizeof (*r)) == 0) + { + decNumberFromString (dn, "0.5", &set); + break; + } + gcc_unreachable (); + } decimal128ToNumber ((const decimal128 *) r->sig, dn); break; default: --- gcc/testsuite/gcc.dg/dfp/pr48928.c.jj 2011-05-09 11:23:59.000000000 +0200 +++ gcc/testsuite/gcc.dg/dfp/pr48928.c 2011-05-09 11:23:24.000000000 +0200 @@ -0,0 +1,10 @@ +/* PR debug/48928 */ +/* { dg-do compile } */ +/* { dg-options "-g -O2" } */ + +_Decimal32 +foo (_Decimal32 x) +{ + _Decimal32 y = (x + x) / (9.DF * x); + return y; +}