aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/gcc-interface
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2024-11-04 12:14:52 +0100
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-11-14 14:54:31 +0100
commit01413da3b0c5cfd70db63fff4c033ae83a4dcb0f (patch)
tree3726ceec4d99faf2908566ebeb82d46eaa64ee97 /gcc/ada/gcc-interface
parent29112f5e1b2a8751349943f72c046e7ad3c8de8e (diff)
downloadgcc-01413da3b0c5cfd70db63fff4c033ae83a4dcb0f.zip
gcc-01413da3b0c5cfd70db63fff4c033ae83a4dcb0f.tar.gz
gcc-01413da3b0c5cfd70db63fff4c033ae83a4dcb0f.tar.bz2
ada: Avoid doing unnecessary work in elaborate_expression_2
This prevents the expression from being tweaked by the match.pd machinery in the process, which can damage the readability of the -gnatR3 output. gcc/ada/ChangeLog: * gcc-interface/decl.cc (elaborate_expression_2): Do not divide and multiply back if the alignment factor is already explicit.
Diffstat (limited to 'gcc/ada/gcc-interface')
-rw-r--r--gcc/ada/gcc-interface/decl.cc33
1 files changed, 24 insertions, 9 deletions
diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index 32e476c..024bf45 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -7355,15 +7355,30 @@ static tree
elaborate_expression_2 (tree gnu_expr, Entity_Id gnat_entity, const char *s,
bool definition, bool need_for_debug, unsigned int align)
{
- tree unit_align = size_int (align / BITS_PER_UNIT);
- return
- size_binop (MULT_EXPR,
- elaborate_expression_1 (size_binop (EXACT_DIV_EXPR,
- gnu_expr,
- unit_align),
- gnat_entity, s, definition,
- need_for_debug),
- unit_align);
+ /* Nothing more to do if the factor is already explicit in the tree. */
+ if (TREE_CODE (gnu_expr) == MULT_EXPR
+ && TREE_CONSTANT (TREE_OPERAND (gnu_expr, 1))
+ && value_factor_p (TREE_OPERAND (gnu_expr, 1), align / BITS_PER_UNIT))
+ return
+ size_binop (MULT_EXPR,
+ elaborate_expression_1 (TREE_OPERAND (gnu_expr, 0),
+ gnat_entity, s, definition,
+ need_for_debug),
+ TREE_OPERAND (gnu_expr, 1));
+
+ /* Otherwise divide by the factor, elaborate the result and multiply back. */
+ else
+ {
+ tree unit_align = size_int (align / BITS_PER_UNIT);
+ return
+ size_binop (MULT_EXPR,
+ elaborate_expression_1 (size_binop (EXACT_DIV_EXPR,
+ gnu_expr,
+ unit_align),
+ gnat_entity, s, definition,
+ need_for_debug),
+ unit_align);
+ }
}
/* Structure to hold internal data for elaborate_reference. */