This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to remove excess NOP stripping
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 20 Mar 2005 15:24:45 +0000 (UTC)
- Subject: Patch to remove excess NOP stripping
Where an integer constant expression is expected in the C front end,
there is no need to strip NOPs as such an expression will already have
been parsed and folded to an INTEGER_CST (as indeed will many
expressions which are not integer constant expressions): you won't get
INTEGER_CSTs encapsulated in NOP_EXPRs in such circumstances; the same
applied also to code shared with C++ (attribute handlers). This
patch removes various such unnecessary NOP stripping. Bootstrapped
with no regressions on x86_64-unknown-linux-gnu. Applied to mainline.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
joseph@codesourcery.com (CodeSourcery mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)
2005-03-20 Joseph S. Myers <joseph@codesourcery.com>
* c-common.c (handle_aligned_attribute, check_function_sentinel,
get_nonnull_operand, handle_sentinel_attribute,
check_function_arguments_recurse): Do not strip NOPS from
INTEGER_CSTs.
* c-decl.c (check_bitfield_type_and_width, build_enumerator):
Likewise.
* c-format.c (get_constant): Likewise.
* c-parser.c (c_parser_postfix_expression): Likewise.
* c-typeck.c (set_init_index): Likewise.
(convert_arguments): Don't check for NOP_EXPR containing integer
constant.
diff -rupN GCC.orig/gcc/c-common.c GCC/gcc/c-common.c
--- GCC.orig/gcc/c-common.c 2005-03-18 20:45:08.000000000 +0000
+++ GCC/gcc/c-common.c 2005-03-20 02:33:59.000000000 +0000
@@ -4481,12 +4481,6 @@ handle_aligned_attribute (tree *node, tr
else if (TYPE_P (*node))
type = node, is_type = 1;
- /* Strip any NOPs of any kind. */
- while (TREE_CODE (align_expr) == NOP_EXPR
- || TREE_CODE (align_expr) == CONVERT_EXPR
- || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
- align_expr = TREE_OPERAND (align_expr, 0);
-
if (TREE_CODE (align_expr) != INTEGER_CST)
{
error ("requested alignment is not a constant");
@@ -5119,7 +5113,6 @@ check_function_sentinel (tree attrs, tre
if (TREE_VALUE (attr))
{
tree p = TREE_VALUE (TREE_VALUE (attr));
- STRIP_NOPS (p);
pos = TREE_INT_CST_LOW (p);
}
@@ -5199,13 +5192,7 @@ check_nonnull_arg (void * ARG_UNUSED (ct
static bool
get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
{
- /* Strip any conversions from the arg number and verify they
- are constants. */
- while (TREE_CODE (arg_num_expr) == NOP_EXPR
- || TREE_CODE (arg_num_expr) == CONVERT_EXPR
- || TREE_CODE (arg_num_expr) == NON_LVALUE_EXPR)
- arg_num_expr = TREE_OPERAND (arg_num_expr, 0);
-
+ /* Verify the arg number is a constant. */
if (TREE_CODE (arg_num_expr) != INTEGER_CST
|| TREE_INT_CST_HIGH (arg_num_expr) != 0)
return false;
@@ -5324,7 +5311,6 @@ handle_sentinel_attribute (tree *node, t
{
tree position = TREE_VALUE (args);
- STRIP_NOPS (position);
if (TREE_CODE (position) != INTEGER_CST)
{
warning ("requested position is not an integer constant");
@@ -5402,10 +5388,6 @@ check_function_arguments_recurse (void (
/* Extract the argument number, which was previously checked
to be valid. */
format_num_expr = TREE_VALUE (TREE_VALUE (attrs));
- while (TREE_CODE (format_num_expr) == NOP_EXPR
- || TREE_CODE (format_num_expr) == CONVERT_EXPR
- || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
- format_num_expr = TREE_OPERAND (format_num_expr, 0);
gcc_assert (TREE_CODE (format_num_expr) == INTEGER_CST
&& !TREE_INT_CST_HIGH (format_num_expr));
diff -rupN GCC.orig/gcc/c-decl.c GCC/gcc/c-decl.c
--- GCC.orig/gcc/c-decl.c 2005-03-20 01:48:47.000000000 +0000
+++ GCC/gcc/c-decl.c 2005-03-20 02:30:52.000000000 +0000
@@ -3637,9 +3637,6 @@ check_bitfield_type_and_width (tree *typ
unsigned HOST_WIDE_INT w;
const char *name = orig_name ? orig_name: _("<anonymous>");
- /* Necessary? */
- STRIP_NOPS (*width);
-
/* Detect and ignore out of range field width and process valid
field widths. */
if (!INTEGRAL_TYPE_P (TREE_TYPE (*width))
@@ -5624,10 +5621,6 @@ build_enumerator (tree name, tree value)
/* Validate and default VALUE. */
- /* Remove no-op casts from the value. */
- if (value)
- STRIP_TYPE_NOPS (value);
-
if (value != 0)
{
/* Don't issue more errors for error_mark_node (i.e. an
diff -rupN GCC.orig/gcc/c-format.c GCC/gcc/c-format.c
--- GCC.orig/gcc/c-format.c 2005-03-18 20:45:08.000000000 +0000
+++ GCC/gcc/c-format.c 2005-03-20 02:35:07.000000000 +0000
@@ -147,17 +147,12 @@ check_format_string (tree argument, unsi
return true;
}
-/* Strip any conversions from the expression, verify it is a constant,
- and store its value. If validated_p is true, abort on errors.
+/* Verify EXPR is a constant, and store its value.
+ If validated_p is true, abort on errors.
Returns true on success, false otherwise. */
static bool
get_constant (tree expr, unsigned HOST_WIDE_INT *value, int validated_p)
{
- while (TREE_CODE (expr) == NOP_EXPR
- || TREE_CODE (expr) == CONVERT_EXPR
- || TREE_CODE (expr) == NON_LVALUE_EXPR)
- expr = TREE_OPERAND (expr, 0);
-
if (TREE_CODE (expr) != INTEGER_CST || TREE_INT_CST_HIGH (expr) != 0)
{
gcc_assert (!validated_p);
diff -rupN GCC.orig/gcc/c-parser.c GCC/gcc/c-parser.c
--- GCC.orig/gcc/c-parser.c 2005-03-13 01:07:03.000000000 +0000
+++ GCC/gcc/c-parser.c 2005-03-20 02:35:30.000000000 +0000
@@ -5019,7 +5019,6 @@ c_parser_postfix_expression (c_parser *p
tree c;
c = fold (e1.value);
- STRIP_NOPS (c);
if (TREE_CODE (c) != INTEGER_CST)
error ("first argument to %<__builtin_choose_expr%> not"
" a constant");
diff -rupN GCC.orig/gcc/c-typeck.c GCC/gcc/c-typeck.c
--- GCC.orig/gcc/c-typeck.c 2005-03-18 20:45:08.000000000 +0000
+++ GCC/gcc/c-typeck.c 2005-03-20 02:40:28.000000000 +0000
@@ -2234,11 +2234,6 @@ convert_arguments (tree typelist, tree v
/* Change in signedness doesn't matter
if a constant value is unaffected. */
;
- /* Likewise for a constant in a NOP_EXPR. */
- else if (TREE_CODE (val) == NOP_EXPR
- && TREE_CODE (TREE_OPERAND (val, 0)) == INTEGER_CST
- && int_fits_type_p (TREE_OPERAND (val, 0), type))
- ;
/* If the value is extended from a narrower
unsigned type, it doesn't matter whether we
pass it as signed or unsigned; the value
@@ -5205,21 +5200,6 @@ set_init_index (tree first, tree last)
return;
}
- while ((TREE_CODE (first) == NOP_EXPR
- || TREE_CODE (first) == CONVERT_EXPR
- || TREE_CODE (first) == NON_LVALUE_EXPR)
- && (TYPE_MODE (TREE_TYPE (first))
- == TYPE_MODE (TREE_TYPE (TREE_OPERAND (first, 0)))))
- first = TREE_OPERAND (first, 0);
-
- if (last)
- while ((TREE_CODE (last) == NOP_EXPR
- || TREE_CODE (last) == CONVERT_EXPR
- || TREE_CODE (last) == NON_LVALUE_EXPR)
- && (TYPE_MODE (TREE_TYPE (last))
- == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last, 0)))))
- last = TREE_OPERAND (last, 0);
-
if (TREE_CODE (first) != INTEGER_CST)
error_init ("nonconstant array index in initializer");
else if (last != 0 && TREE_CODE (last) != INTEGER_CST)