From patchwork Thu Sep 19 13:28:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1164613 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-509275-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Y2xe2tG7"; dkim-atps=neutral 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 46YyPQ0RlMz9sN1 for ; Thu, 19 Sep 2019 23:29:29 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=FzN4VhNJYuZ1AN4Em7x1Rtq02yTwMRXf3wc4a6GjNee+OgPh2V Vpc+jx8jB8sgyj9GlDFVDJGgJityQjU0Tmbm6gB1sbMRn43+Gw8jBs4GN6e8mABm 9DbcVZre7EIhBNUjCVWf1yvFymHjeUxPbOb5atmcy7o7tlMuruFM7iJ4k= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=nw0NtgtQKeH3cLi/lmZXGn7WLUo=; b=Y2xe2tG7x1DMtgNPjC6X VEtgs7CzCyX8dEMnvf7/2duwnfJT0zA+VbDv8yI2DPwOs5Ejwt6s9wb1OiH/DlP2 rM3JCQ6u5+aq/XQaNj/fAq2BOdlc/6fZcasLG5BQ3VMzxiDZmNb64s6wkqfINWad KKdlywc8P3rUMMknT6lfGXk= Received: (qmail 1380 invoked by alias); 19 Sep 2019 13:28:26 -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 1315 invoked by uid 89); 19 Sep 2019 13:28:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=exp_attr, sk:N_Attri, Attribute_Name, Exp_Attr X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Sep 2019 13:28:24 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 94AC056029; Thu, 19 Sep 2019 09:28:19 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id gjz2RX9fJPtO; Thu, 19 Sep 2019 09:28:19 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 7DD875601D; Thu, 19 Sep 2019 09:28:19 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 786466B4; Thu, 19 Sep 2019 09:28:19 -0400 (EDT) Date: Thu, 19 Sep 2019 09:28:19 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Implement Machine_Rounding attribute in line when possible Message-ID: <20190919132819.GA41780@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes GNAT implements Machine_Rounding as an alias for Rounding but, whereas the implementation of the latter is in line when possible, that of the former is always out of line, which is not aligned with the intent of the Ada RM. This changes the compiler to using for Machine_Rounding the same in line implementation as Rounding when possible. Running these commands: gcc -c f.adb -gnatD grep system f.adb.dg On the following sources: function F (Val : Float) return Integer is begin return Integer (Float'Machine_Rounding (Val)); end; Should execute silently. Tested on x86_64-pc-linux-gnu, committed on trunk 2019-09-19 Eric Botcazou gcc/ada/ * exp_attr.adb (Is_Inline_Floating_Point_Attribute): Treat Machine_Rounding as an alias for Rounding. * sem_res.adb (Simplify_Type_Conversion): Likewise. --- gcc/ada/exp_attr.adb +++ gcc/ada/exp_attr.adb @@ -8360,13 +8360,13 @@ package body Exp_Attr is return False; end if; - -- Here we are in the integer conversion context + -- Here we are in the integer conversion context. We reuse Rounding for + -- Machine_Rounding as System.Fat_Gen, which is a permissible behavior. - -- Very probably we should also recognize the cases of Machine_Rounding - -- and unbiased rounding in this conversion context, but the back end is - -- not yet prepared to handle these cases ??? - - return Id = Attribute_Rounding or else Id = Attribute_Truncation; + return + Id = Attribute_Rounding + or else Id = Attribute_Machine_Rounding + or else Id = Attribute_Truncation; end Is_Inline_Floating_Point_Attribute; end Exp_Attr; --- gcc/ada/sem_res.adb +++ gcc/ada/sem_res.adb @@ -12439,7 +12439,8 @@ package body Sem_Res is -- ityp (x) -- with the Float_Truncate flag set to False or True respectively, - -- which is more efficient. + -- which is more efficient. We reuse Rounding for Machine_Rounding + -- as System.Fat_Gen, which is a permissible behavior. if Is_Floating_Point_Type (Opnd_Typ) and then @@ -12448,6 +12449,7 @@ package body Sem_Res is and then Conversion_OK (N))) and then Nkind (Operand) = N_Attribute_Reference and then Nam_In (Attribute_Name (Operand), Name_Rounding, + Name_Machine_Rounding, Name_Truncation) then declare