public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] Optimize nonstandard boolean validity checking
@ 2022-05-06  7:18 Alexandre Oliva
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 2022-05-06  7:18 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4b916d8437e76146b1bdb20391b016e8461e8382

commit 4b916d8437e76146b1bdb20391b016e8461e8382
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Thu Feb 17 03:12:04 2022 -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) <Attribute_Valid>: 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gcc(refs/users/aoliva/heads/testme)] Optimize nonstandard boolean validity checking
@ 2022-01-27  9:49 Alexandre Oliva
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 2022-01-27  9:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5f92aa1218d2171e4f479eafc95414561f7f4417

commit 5f92aa1218d2171e4f479eafc95414561f7f4417
Author: Alexandre Oliva <oliva@adacore.com>
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) <Attribute_Valid>: 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-06  7:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06  7:18 [gcc(refs/users/aoliva/heads/testme)] Optimize nonstandard boolean validity checking Alexandre Oliva
  -- strict thread matches above, loose matches on Subject: below --
2022-01-27  9:49 Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).