Message ID | 20130115153856.GX7269@tucnak.redhat.com |
---|---|
State | New |
Headers | show |
On Tue, 15 Jan 2013, Jakub Jelinek wrote: > Hi! > > This patch fixes ICE on the attached testcase on ARM, where we ended up > creating invalid debug stmt, which had SImode var on the lhs, but BLKmode > MEM_REF on the rhs. Fixed by matching (almost, with the build_ref_for_model > -> build_debug_ref_for_model change) what we do for normal stmt > modifications earlier. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Works for me. Thanks, Richard. > 2013-01-15 Jakub Jelinek <jakub@redhat.com> > > PR tree-optimization/55920 > * tree-sra.c (sra_modify_assign): If for lacc->grp_to_be_debug_replaced > there is non-useless type conversion needed from debug rhs to lhs, > use build_debug_ref_for_model and/or VIEW_CONVERT_EXPR. > > * gcc.c-torture/compile/pr55920.c: New test. > > --- gcc/tree-sra.c.jj 2013-01-11 09:02:55.000000000 +0100 > +++ gcc/tree-sra.c 2013-01-15 12:52:01.161324202 +0100 > @@ -3108,8 +3108,20 @@ sra_modify_assign (gimple *stmt, gimple_ > > if (lacc && lacc->grp_to_be_debug_replaced) > { > - gimple ds = gimple_build_debug_bind (get_access_replacement (lacc), > - unshare_expr (rhs), *stmt); > + tree debug_lhs = get_access_replacement (lacc); > + tree debug_rhs = unshare_expr (rhs); > + if (!useless_type_conversion_p (TREE_TYPE (debug_lhs), > + TREE_TYPE (debug_rhs))) > + { > + if (AGGREGATE_TYPE_P (TREE_TYPE (debug_rhs)) > + && !contains_vce_or_bfcref_p (debug_rhs)) > + debug_rhs = build_debug_ref_for_model (loc, debug_rhs, 0, lacc); > + if (!useless_type_conversion_p (TREE_TYPE (debug_lhs), > + TREE_TYPE (debug_rhs))) > + debug_rhs = fold_build1_loc (loc, VIEW_CONVERT_EXPR, > + TREE_TYPE (debug_lhs), debug_rhs); > + } > + gimple ds = gimple_build_debug_bind (debug_lhs, debug_rhs, *stmt); > gsi_insert_before (gsi, ds, GSI_SAME_STMT); > } > > --- gcc/testsuite/gcc.c-torture/compile/pr55920.c.jj 2013-01-15 12:58:01.782125163 +0100 > +++ gcc/testsuite/gcc.c-torture/compile/pr55920.c 2013-01-15 12:57:23.000000000 +0100 > @@ -0,0 +1,16 @@ > +/* PR tree-optimization/55920 */ > + > +struct A { unsigned a; } __attribute__((packed)); > +struct B { int b; unsigned char c[16]; }; > +void bar (struct A); > + > +void > +foo (struct B *x) > +{ > + struct A a; > + if (x->b) > + __builtin_memcpy (&a, x->c, sizeof a); > + else > + a.a = 0; > + bar (a); > +} > > Jakub > >
--- gcc/tree-sra.c.jj 2013-01-11 09:02:55.000000000 +0100 +++ gcc/tree-sra.c 2013-01-15 12:52:01.161324202 +0100 @@ -3108,8 +3108,20 @@ sra_modify_assign (gimple *stmt, gimple_ if (lacc && lacc->grp_to_be_debug_replaced) { - gimple ds = gimple_build_debug_bind (get_access_replacement (lacc), - unshare_expr (rhs), *stmt); + tree debug_lhs = get_access_replacement (lacc); + tree debug_rhs = unshare_expr (rhs); + if (!useless_type_conversion_p (TREE_TYPE (debug_lhs), + TREE_TYPE (debug_rhs))) + { + if (AGGREGATE_TYPE_P (TREE_TYPE (debug_rhs)) + && !contains_vce_or_bfcref_p (debug_rhs)) + debug_rhs = build_debug_ref_for_model (loc, debug_rhs, 0, lacc); + if (!useless_type_conversion_p (TREE_TYPE (debug_lhs), + TREE_TYPE (debug_rhs))) + debug_rhs = fold_build1_loc (loc, VIEW_CONVERT_EXPR, + TREE_TYPE (debug_lhs), debug_rhs); + } + gimple ds = gimple_build_debug_bind (debug_lhs, debug_rhs, *stmt); gsi_insert_before (gsi, ds, GSI_SAME_STMT); } --- gcc/testsuite/gcc.c-torture/compile/pr55920.c.jj 2013-01-15 12:58:01.782125163 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr55920.c 2013-01-15 12:57:23.000000000 +0100 @@ -0,0 +1,16 @@ +/* PR tree-optimization/55920 */ + +struct A { unsigned a; } __attribute__((packed)); +struct B { int b; unsigned char c[16]; }; +void bar (struct A); + +void +foo (struct B *x) +{ + struct A a; + if (x->b) + __builtin_memcpy (&a, x->c, sizeof a); + else + a.a = 0; + bar (a); +}