On Mon, Jun 16, 2014 at 01:38:49PM +0200, Richard Biener wrote:
> On Mon, Jun 16, 2014 at 12:57 PM, Bernd Schmidt <ber...@codesourcery.com> 
> wrote:
> > There's code in regimplification that makes us use an extra temporary
> > when we encounter a call returning a non-BLKmode structure. This seems
> > somewhat inefficient and unnecessary, and when used from the
> > lower-addr-spaces pass I'm working on it leads to problems further
> > down that look like tree-ssa bugs that I wasn't able to clearly
> > disentangle.
> >
> > Here's what happens on compile/pr51761.c.  Regimplification has the
> > following effect, creating an extra temporary _6:
> >
> > -  D.1378 = fooD.1373 (aD.1377);
> > +  _6 = fooD.1373 (aD.1377);
> > +  # .MEMD.1382 = VDEF <.MEMD.1382>
> > +  D.1378 = _6;
> >
> > SRA turns this into:
> >
> >   _6 = fooD.1373 (aD.1377);
> >   # VUSE <.MEM_3>
> >   SR$2_7 = MEM[(struct S *)&_6];
> 
> clearly bogus - _6 is a register, you can't use a MEM on it.

Weird... does the following (untested) patch help?

diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c
index 0afa197..747b1b6 100644
--- a/gcc/tree-sra.c
+++ b/gcc/tree-sra.c
@@ -3277,6 +3277,8 @@ sra_modify_assign (gimple *stmt, gimple_stmt_iterator 
*gsi)
 
   if (modify_this_stmt
       || gimple_has_volatile_ops (*stmt)
+      || is_gimple_reg (lhs)
+      || is_gimple_reg (rhs)
       || contains_vce_or_bfcref_p (rhs)
       || contains_vce_or_bfcref_p (lhs)
       || stmt_ends_bb_p (*stmt))

It is just a quick thought though.  If it does not, could you post the
access trees dumped by -fdump-tree-esra-details or
-fdump-tree-sra-details (depending on whether this is early or late
SRA)?  Or is it simple to set it up locally?

Thanks,

Martin

> 
> > Somehow, the address of &_6 doesn't count as a use, and the DCE pass decides
> > it is unused:
> >
> >   Eliminating unnecessary statements:
> >   Deleting LHS of call: _6 = foo (a);
> >
> > However, the statement
> >   SR$2_7 = MEM[(struct S *)&_6];
> > is still present, and we have an SSA name without a definition, leading to a
> > crash.
> >
> > Rather than figure all this out, I decided to try making the
> > regimplification not generate the extra copy in the first place. The
> > testsuite seems to agree with me that it's unnecessary. Bootstrapped and
> > tested on x86_64-linux, ok?
> 
> Ok.  The code looks bogus anyway in that it generates a SSA name
> for sth not is_gimple_reg_type ().
> 
> Thanks,
> Richard.
> 
> >
> > Bernd

Reply via email to