From patchwork Mon Oct 9 21:03:56 2017 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: 823517 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-463826-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="fUGFrGEO"; 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 3y9t5h1D8sz9t5Q for ; Tue, 10 Oct 2017 08:04:07 +1100 (AEDT) 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=kqebsfsnnowinyaC+U0Bj6OcT+GV7uVesAjyj+xQpJ35OD/vfL uPPEUvCmDfmNYqw6A6Ppo3lPGqbjeY02xCV40j334FhpJV7KuXrg1KrAGRfXF2Fr hldUewZh3DeF7cTD/x3OV2x9ZO123p4riIXmomA4fPwFxCVh+vWspPSHA= 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=9bUqFQyKeDd3FAFw9vEKENfII4A=; b=fUGFrGEOfzaG3B+jCs9R bEhKds36ghkuDE0zLyIzAgd/bo2eFnfotramKEd+n+wl3znh8TP4ufzO+V47WrDS 1LqAuZtK0BxAMqL7yNecRzHrhSC4V9TXRbfff8Hi1SHzqT631UjpOi6ckV2Vymax Xd6Nu4XcRsi+8V414SLXpRY= Received: (qmail 60315 invoked by alias); 9 Oct 2017 21:03:59 -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 60304 invoked by uid 89); 9 Oct 2017 21:03:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS, TO_NO_BRKTS_PCNT autolearn=ham version=3.3.2 spammy= 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; Mon, 09 Oct 2017 21:03:57 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 7D2A85632C; Mon, 9 Oct 2017 17:03:56 -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 ottah6UUgAbC; Mon, 9 Oct 2017 17:03:56 -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 6CA715632A; Mon, 9 Oct 2017 17:03:56 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 6BA5843A; Mon, 9 Oct 2017 17:03:56 -0400 (EDT) Date: Mon, 9 Oct 2017 17:03:56 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Small optimizations in Sem_Type.Covers Message-ID: <20171009210356.GA23865@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes The Sem_Type.Covers predicate is by far the topmost subprogram in the profile of unoptimized compilations in Ada. This change contains a series of small optimizations that save about 2% of the instruction count on x86-64: 1. Inline 3 more predicates from einfo, 2. Simplify a convoluted condition dealing with Standard_Void_Type, 3. Move up cheap tests on T2 so that they are executed before more costly tests on T1, 4. Move the Is_Private_Type test from Full_View_Covers to the main body and remove tests on base types that were already done in the main body. The main saving stems from 4. because tests on In_Instance are now guarded by the Is_Private_Type predicate and In_Instance is quite costly since it climbs the scope chain on each invocation. No functional changes. Tested on x86_64-pc-linux-gnu, committed on trunk 2017-10-09 Eric Botcazou * einfo.ads (Is_Boolean_Type): Add pragma Inline. (Is_Entity_Name): Likewise. (Is_String_Type): Likewise. * sem_type.adb (Full_View_Covers): Do not test Is_Private_Type here and remove useless comparisons on the base types. (Covers): Use simple tests for Standard_Void_Type. Move up cheap tests on T2. Always test Is_Private_Type before Full_View_Covers. Index: einfo.ads =================================================================== --- einfo.ads (revision 253559) +++ einfo.ads (working copy) @@ -9470,9 +9470,12 @@ pragma Inline (Base_Type); pragma Inline (Is_Base_Type); + pragma Inline (Is_Boolean_Type); pragma Inline (Is_Controlled); + pragma Inline (Is_Entity_Name); pragma Inline (Is_Package_Or_Generic_Package); pragma Inline (Is_Packed_Array); + pragma Inline (Is_String_Type); pragma Inline (Is_Subprogram_Or_Generic_Subprogram); pragma Inline (Is_Volatile); pragma Inline (Is_Wrapper_Package); Index: sem_type.adb =================================================================== --- sem_type.adb (revision 253546) +++ sem_type.adb (working copy) @@ -761,15 +761,19 @@ function Full_View_Covers (Typ1, Typ2 : Entity_Id) return Boolean is begin - return - Is_Private_Type (Typ1) - and then - ((Present (Full_View (Typ1)) - and then Covers (Full_View (Typ1), Typ2)) - or else (Present (Underlying_Full_View (Typ1)) - and then Covers (Underlying_Full_View (Typ1), Typ2)) - or else Base_Type (Typ1) = Typ2 - or else Base_Type (Typ2) = Typ1); + if Present (Full_View (Typ1)) + and then Covers (Full_View (Typ1), Typ2) + then + return True; + + elsif Present (Underlying_Full_View (Typ1)) + and then Covers (Underlying_Full_View (Typ1), Typ2) + then + return True; + + else + return False; + end if; end Full_View_Covers; ----------------- @@ -825,7 +829,7 @@ -- Standard_Void_Type is a special entity that has some, but not all, -- properties of types. - if (T1 = Standard_Void_Type) /= (T2 = Standard_Void_Type) then + if T1 = Standard_Void_Type or else T2 = Standard_Void_Type then return False; end if; @@ -892,8 +896,8 @@ or else (T2 = Universal_Real and then Is_Real_Type (T1)) or else (T2 = Universal_Fixed and then Is_Fixed_Point_Type (T1)) or else (T2 = Any_Fixed and then Is_Fixed_Point_Type (T1)) + or else (T2 = Any_Character and then Is_Character_Type (T1)) or else (T2 = Any_String and then Is_String_Type (T1)) - or else (T2 = Any_Character and then Is_Character_Type (T1)) or else (T2 = Any_Access and then Is_Access_Type (T1)) then return True; @@ -916,9 +920,9 @@ -- task_type or protected_type that implements the interface. elsif Ada_Version >= Ada_2005 + and then Is_Concurrent_Type (T2) and then Is_Class_Wide_Type (T1) and then Is_Interface (Etype (T1)) - and then Is_Concurrent_Type (T2) and then Interface_Present_In_Ancestor (Typ => BT2, Iface => Etype (T1)) then @@ -928,9 +932,9 @@ -- object T2 implementing T1. elsif Ada_Version >= Ada_2005 + and then Is_Tagged_Type (T2) and then Is_Class_Wide_Type (T1) and then Is_Interface (Etype (T1)) - and then Is_Tagged_Type (T2) then if Interface_Present_In_Ancestor (Typ => T2, Iface => Etype (T1)) @@ -1183,19 +1187,16 @@ -- whether a partial and a full view match. Verify that types are -- legal, to prevent cascaded errors. - elsif In_Instance - and then (Full_View_Covers (T1, T2) or else Full_View_Covers (T2, T1)) - then - return True; - - elsif Is_Type (T2) - and then Is_Generic_Actual_Type (T2) + elsif Is_Private_Type (T1) + and then (In_Instance + or else (Is_Type (T2) and then Is_Generic_Actual_Type (T2))) and then Full_View_Covers (T1, T2) then return True; - elsif Is_Type (T1) - and then Is_Generic_Actual_Type (T1) + elsif Is_Private_Type (T2) + and then (In_Instance + or else (Is_Type (T1) and then Is_Generic_Actual_Type (T1))) and then Full_View_Covers (T2, T1) then return True;