This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
improve c variable size array indexing
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 18 Dec 2004 19:53:31 -0800
- Subject: improve c variable size array indexing
The other day I was bitching about the
t.1 = n - 1
t.2 = t.1 * 8
t.3 = t.2 + 8
thing. Turns out that if we just move the SAVE_EXPR inside the
subtraction than fold can magically get rid of it all. Whee!
Tested on i686-linux.
r~
* c-decl.c (grokdeclarator): Save variable array size before
subtracting 1, rather than after.
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.613
diff -c -p -d -u -r1.613 c-decl.c
--- c-decl.c 17 Dec 2004 20:05:24 -0000 1.613
+++ c-decl.c 19 Dec 2004 03:34:59 -0000
@@ -4084,6 +4084,12 @@ grokdeclarator (const struct c_declarato
}
else
{
+ /* Arrange for the SAVE_EXPR on the inside of the
+ MINUS_EXPR, which allows the -1 to get folded
+ with the +1 that happens when building TYPE_SIZE. */
+ if (size_varies)
+ size = variable_size (size);
+
/* Compute the maximum valid index, that is, size
- 1. Do the calculation in index_type, so that
if it is a variable the computations will be
@@ -4107,8 +4113,6 @@ grokdeclarator (const struct c_declarato
continue;
}
- if (size_varies)
- itype = variable_size (itype);
itype = build_index_type (itype);
}
}