This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Optimize byte_from_pos, pos_from_bit
On Wed, 9 May 2012, Eric Botcazou wrote:
> > This optimizes byte_from_pos and pos_from_bit by noting that we operate
> > on sizes whose computations have no intermediate (or final) overflow.
> > This is the single patch necessary to get Ada to bootstrap and test
> > with TYPE_IS_SIZETYPE removed. Rather than amending size_binop
> > (my original plan) I chose to optimize the above two commonly used
> > accessors.
> >
> > Conveniently normalize_offset can be re-written to use pos_from_bit
> > instead of inlinig it. I also took the liberty to document the
> > functions (sic).
>
> Nice, thanks. Could you add a blurb, in the head comment of the first function
> in which you operate under the no-overflow assumption, stating this fact and
> why this is necessary (an explicit mention of Ada isn't forbidden ;-), as well
> as a cross-reference to it in the head comment of the other function(s).
Like this?
Thanks,
Richard.
2012-05-10 Richard Guenther <rguenther@suse.de>
* stor-layout.c (byte_from_pos): Amend comment.
Index: gcc/stor-layout.c
===================================================================
--- gcc/stor-layout.c (revision 187362)
+++ gcc/stor-layout.c (working copy)
@@ -798,7 +798,11 @@ bit_from_pos (tree offset, tree bitpos)
}
/* Return the combined truncated byte position for the byte offset OFFSET and
- the bit position BITPOS. */
+ the bit position BITPOS.
+ These functions operate on byte and bit positions as present in FIELD_DECLs
+ and it assumes that expressions result in no (intermediate) overflow.
+ This assumption is necessary to optimize these values as much as possible,
+ especially to make Ada happy. */
tree
byte_from_pos (tree offset, tree bitpos)