From: Alexandre Oliva Date: Wed, 29 Dec 2021 07:10:46 +0000 (-0300) Subject: [Ada] Optimize nonstandard boolean validity checking X-Git-Tag: basepoints/gcc-14~6955 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b3bd801520e707d113c0f81e028abae023c4d3a;p=thirdparty%2Fgcc.git [Ada] 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. gcc/ada/ * exp_attr.adb (Expand_N_Attribute_Reference) : Drop redundant range check for nonstandard booleans. --- diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb index 7b36daec9ae..cc043513911 100644 --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -7281,7 +7281,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