This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: SRA bit-field optimization
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: rsandifo at nildram dot co dot uk, "Richard Guenther" <richard dot guenther at gmail dot com>
- Cc: "Roman Zippel" <zippel at linux-m68k dot org>, "Bernd Schmidt" <bernds_cb1 at t-online dot de>, "Diego Novillo" <dnovillo at acm dot org>, "Daniel Berlin" <dberlin at dberlin dot org>, "GCC Patches" <gcc-patches at gcc dot gnu dot org>, "Andrew Pinski" <pinskia at gmail dot com>, "Eric Botcazou" <ebotcazou at adacore dot com>
- Date: Wed, 03 Oct 2007 13:49:34 -0300
- Subject: Re: SRA bit-field optimization
- References: <orfy4czoyq.fsf@oliva.athome.lsd.ic.unicamp.br> <Pine.LNX.4.64.0707030240580.1820@scrub.home> <orsl82szfw.fsf@oliva.athome.lsd.ic.unicamp.br> <or8x817e6t.fsf_-_@free.oliva.athome.lsd.ic.unicamp.br> <orzlz7iis1.fsf@free.oliva.athome.lsd.ic.unicamp.br> <84fc9c000710021015p4276c5d2s70c75e13a2225f30@mail.gmail.com> <87tzp8twxh.fsf@firetop.home>
On Oct 3, 2007, Richard Sandiford <rsandifo@nildram.co.uk> wrote:
> For the record, it also causes many failures on mips-linux-gnu,
> such as the following execute.exp ones:
> FWIW, the gcc.c-torture/execute/20000113-1.c failures can easily be
> reproduced with a cross-compiler, because after the patch, foobar is
> optimised to a call to abort.
This patch appears to fix at least the first one. I haven't given it
a full round of testing yet, FWIW.
for gcc/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* tree-sra.c (sra_build_assignment): Set up mask depending on
precision, not type.
(sra_build_elt_assignment): Don't view-convert from signed to
unsigned.
(sra_explode_bitfield_assignment): Use bit-field type if
possible.
Index: gcc/tree-sra.c
===================================================================
--- gcc/tree-sra.c.orig 2007-10-01 17:38:16.000000000 -0300
+++ gcc/tree-sra.c 2007-10-03 13:36:08.000000000 -0300
@@ -2168,7 +2168,7 @@ sra_build_assignment (tree dst, tree src
list = NULL;
cst2 = size_binop (MINUS_EXPR, maxshift, minshift);
- if (tree_int_cst_equal (cst2, TYPE_SIZE (utype)))
+ if (TREE_INT_CST_LOW (cst2) == TYPE_PRECISION (utype))
{
unsignedp = true;
mask = NULL_TREE;
@@ -2508,13 +2508,13 @@ sra_build_elt_assignment (struct sra_elt
{
list = NULL;
- if (!INTEGRAL_TYPE_P (TREE_TYPE (src))
- || !TYPE_UNSIGNED (TREE_TYPE (src)))
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (src)))
src = fold_build1 (VIEW_CONVERT_EXPR,
lang_hooks.types.type_for_size
(TREE_INT_CST_LOW
(TYPE_SIZE (TREE_TYPE (src))),
1), src);
+ gcc_assert (TYPE_UNSIGNED (TREE_TYPE (src)));
tmp = make_rename_temp (TREE_TYPE (src), "SR");
stmt = build_gimple_modify_stmt (tmp, src);
@@ -2971,10 +2971,14 @@ sra_explode_bitfield_assignment (tree va
if (fld->replacement)
{
- tree infld, invar, st;
+ tree infld, invar, st, type;
infld = fld->replacement;
+ type = TREE_TYPE (infld);
+ if (TYPE_PRECISION (type) != TREE_INT_CST_LOW (flen))
+ type = lang_hooks.types.type_for_size (TREE_INT_CST_LOW (flen), 1);
+
if (TREE_CODE (infld) == BIT_FIELD_REF)
{
fpos = size_binop (PLUS_EXPR, fpos, TREE_OPERAND (infld, 2));
@@ -2990,10 +2994,7 @@ sra_explode_bitfield_assignment (tree va
DECL_SIZE (fld->element));
}
- infld = fold_build3 (BIT_FIELD_REF,
- lang_hooks.types.type_for_size
- (TREE_INT_CST_LOW (flen), 1),
- infld, flen, fpos);
+ infld = fold_build3 (BIT_FIELD_REF, type, infld, flen, fpos);
BIT_FIELD_REF_UNSIGNED (infld) = 1;
invar = size_binop (MINUS_EXPR, flp.field_pos, bpos);
@@ -3001,8 +3002,7 @@ sra_explode_bitfield_assignment (tree va
invar = size_binop (PLUS_EXPR, invar, flp.overlap_pos);
invar = size_binop (PLUS_EXPR, invar, vpos);
- invar = fold_build3 (BIT_FIELD_REF, TREE_TYPE (infld),
- var, flen, invar);
+ invar = fold_build3 (BIT_FIELD_REF, type, var, flen, invar);
BIT_FIELD_REF_UNSIGNED (invar) = 1;
if (to_var)
--
Alexandre Oliva http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member http://www.fsfla.org/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}