aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/exp_util.adb
diff options
context:
space:
mode:
authorAlexandre Oliva <oliva@adacore.com>2021-12-29 04:10:46 -0300
committerPierre-Marie de Rodat <derodat@adacore.com>2022-05-10 08:19:30 +0000
commitbf687b8085403b94209269e15491f286644ec10b (patch)
tree733cb752df74e859c1b174f36a19f7e5ecffcdf1 /gcc/ada/exp_util.adb
parent81d33c5c9211dd65b2ffd29424e403582e4542f9 (diff)
downloadgcc-bf687b8085403b94209269e15491f286644ec10b.zip
gcc-bf687b8085403b94209269e15491f286644ec10b.tar.gz
gcc-bf687b8085403b94209269e15491f286644ec10b.tar.bz2
[Ada] Optimize nonstandard boolean conversions
This patch improves the generated code for nonstandard boolean types. One of the improvements extends the code that avoids converting back to the nonstandard boolean type an expression computed as standard boolean, when it will be converted to a(nother) nonstandard boolean type. The other improvement involves using the literal representation constants in an If_Expression instead of dereferencing the T'Val array when converting to a (nonstandard) boolean type. Avoiding the array dereference enables the compiler middle-end to propagate the constants and perform optimizations based on them, to the point of obviating the improvement above. Unfortunately, the code generated with this alternate expansion tends to be slightly larger if it turns out to not enable any further optimization, though it's most certainly faster, especially on targets with conditional moves, more so if "store flag" is slow, as on x86. Still, the array dereference is more straightforward and shorter, so I've arranged for this alternate expansion to be used only when optimizing for speed. gcc/ada/ * exp_util.adb (Adjust_Result_Type): Leave result in Standard.Boolean if it's going to be converted to another boolean type. * exp_ch4.adb (Expand_N_Type_Conversion): When optimizing, convert to nonstandard booleans with an if_expression with boolean literals.
Diffstat (limited to 'gcc/ada/exp_util.adb')
-rw-r--r--gcc/ada/exp_util.adb3
1 files changed, 3 insertions, 0 deletions
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index c28723c..795c1b0 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -424,6 +424,9 @@ package body Exp_Util is
elsif KP in N_Op_Boolean
or else KP in N_Short_Circuit
or else KP = N_Op_Not
+ or else (KP in N_Type_Conversion
+ | N_Unchecked_Type_Conversion
+ and then Is_Boolean_Type (Etype (Parent (N))))
then
return;