From 01413da3b0c5cfd70db63fff4c033ae83a4dcb0f Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Mon, 4 Nov 2024 12:14:52 +0100 Subject: [PATCH] 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. --- gcc/ada/gcc-interface/decl.cc | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc index 32e476c6993..024bf456bc9 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. */