PATCH: fold BIT_AND_EXPR's with ADDR_EXPR operands

Ollie Wild aaw@google.com
Tue Sep 18 09:02:00 GMT 2007


On 9/11/07, Richard Guenther <richard.guenther@gmail.com> wrote:
>
> Can you consolidate your get_lvalue_alignment with
> builtins.c:get_pointer_alignment?
> It seems to have more sophisticated handling of ADDR_EXPRs.

I don't think it makes sense to merge these two functions, as
get_lvalue_alignment tries to calculate the largest modulus yielding a
constant residue, whereas get_pointer_alignment seeks the smallest
modulus yielding a zero residue.  Furthermore, get_pointer_alignment
utilizes TYPE_ALIGN, which is merely suggestive on some architectures
and hence unsuitable for constant folding.

That said, the get_inner_reference function which
get_pointer_alignment uses for offset calculations is perfect.  I've
attached a new patch which adds calls to get_inner_reference for
offset calculations and handles MULT_EXPR operands of
POINTER_PLUS_EXPR.  The latter allows it to handle code like
(unsigned)&a[i] & 3, where the array index is variable.

In theory, I could also handle MULT_EXPR's returned from
get_inner_reference.  However, it isn't clear to me how to generate
such an expression, and I refuse to write code I can't test.  If
someone knows how to write a simple test program for this scenario,
please let me know.

Tested with a full bootstrap and testsuite on i686-pc-linux-gnu.

Ollie

2007-09-17  Ollie Wild  <aaw@google.com>

      fold-const.c (fold_binary): Fold BIT_AND_EXPR's with a pointer operand.
      (get_pointer_modulus_and_residue): New function.

2007-09-07  Ollie Wild  <aaw@google.com>

      gcc.dg/fold-bitand-1.c: New test.
      gcc.dg/fold-bitand-2.c: New test.
      gcc.dg/fold-bitand-3.c: New test.
      gcc.dg/fold-bitand-4.c: New test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fold-bitand.patch
Type: text/x-patch
Size: 7440 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070918/8c55eaa0/attachment.bin>


More information about the Gcc-patches mailing list