On Tue, Dec 13, 2011 at 01:26:42PM +0100, Tom de Vries wrote:
> 2011-12-13  Tom de Vries  <t...@codesourcery.com>
> 
>       PR tree-optimization/51491
>       * tree-ssa-ccp.c (insert_clobber_before_stack_restore): New function.
>       (ccp_fold_stmt): Use insert_clobber_before_stack_restore after a
>       successful fold_builtin_alloca_with_align.

I don't think this is safe.  You don't want to look for any following
__builtin_stack_restore, but for the matching one.  Consider:

int g (int *);

int
f (int n)
{
  int tt = 0;
  int t = 4;
  {
    int a[t
#ifdef DIFFERENT_BB2
          + (tt != 0 ? 6 : 0)
#endif
         ];
    tt = g (a);
    {
      int b[n];
      tt += g (b);
#ifdef DIFFERENT_BB
      if (n > 20)
        tt += 148 * g (b);
#endif      
      tt += b[0];
    }
    tt += a[0];
  }
  {
    int a[4];
    tt += g (a);
    tt += a[0];
  }
  return tt;
}

Without any defines, this shows that looking for the first
BUILT_IN_STACK_RESTORE is wrong if you ignore BUILT_IN_STACK_SAVE calls.
And with the various defines it shows that neither the corresponding
__builtin_stack_save nor __builtin_stack_restore have to be in the same
bb as __builtin_alloca_with_align that is being folded.
Perhaps you want to look for the closest enclosing __builtin_stack_save
(search backwards in current basic block, its immediate dominator etc.?),
remember what SSA_NAME it stores its result into and then just look at
where is the (single?) user of that, which ought to be
__builtin_stack_restore.

        Jakub

Reply via email to