From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id 0F7C13947413; Thu, 27 Jan 2022 09:49:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F7C13947413 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] Optimize nonstandard boolean validity checking X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/testme X-Git-Oldrev: 9ef0e43f0308c518fc4bab7bde9478715dae122e X-Git-Newrev: 5f92aa1218d2171e4f479eafc95414561f7f4417 Message-Id: <20220127094930.0F7C13947413@sourceware.org> Date: Thu, 27 Jan 2022 09:49:30 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jan 2022 09:49:30 -0000 https://gcc.gnu.org/g:5f92aa1218d2171e4f479eafc95414561f7f4417 commit 5f92aa1218d2171e4f479eafc95414561f7f4417 Author: Alexandre Oliva Date: Wed Dec 29 08:44:57 2021 -0300 Optimize nonstandard boolean validity checking Validity checking of enumerations with nonstandard representation starts by checking the value range, then calling _rep_to_pos to verify that the value itself is valid. The value range check is thus redundant and inefficient: the _rep_to_pos call is normally inlined when optimizing for speed and the range check slows down the fast path; it is unnecesary and undesirable when optimizing for size, and just unnecessary when not optimizing. This patch thus drops the range check for nonstandard boolean types. [changelog] * exp_attr.adb (Expand_N_Attribute_Reference) : Drop redundant range check for nonstandard booleans. Diff: --- gcc/ada/exp_attr.adb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb index 5374dd4d7e9..c31d7e06d45 100644 --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -7254,7 +7254,11 @@ package body Exp_Attr is New_Occurrence_Of (Standard_False, Loc))), Right_Opnd => Make_Integer_Literal (Loc, 0)); - if Ptyp /= PBtyp + -- Skip the range test for boolean types, as it buys us + -- nothing. The function called above already fails for + -- values different from both True and False. + + if Ptyp /= PBtyp and then not Is_Boolean_Type (PBtyp) and then (Type_Low_Bound (Ptyp) /= Type_Low_Bound (PBtyp) or else