On Tue, Mar 25, 2014 at 10:15:37AM +0100, Richard Biener wrote:
> On Tue, 25 Mar 2014, Richard Biener wrote:
> > > While working on previous patch, I've noticed a severe omission in the
> > > -fsanitize=signed-integer-overflow support.  Nothing ever
> > > folds addition/subtraction of 0 and multiplication by [0,1], none of these
> > > may ever overflow and thus we can fold them to normal operations and let
> > > those be folded as normal operations.
> > > 
> > > Bootstrapped/regtested on x86_64-linux and i686-linux, tested with
> > > --with-build-config=bootstrap-ubsan bootstrap on i686-linux, ok for trunk?
> > 
> > I think you only need to adjust gimple_fold_stmt_to_constant_1.
> 
> Actually there only for a * 0 and a - a, as others don't result in
> constants.  Still the other cases should be handled in fold_stmt,
> not only in VRP.

IMHO we need even the VRP case, at least for multiplication, otherwise
we wouldn't optimize say:
int
baz (int x, int y)
{
  if (y < 32 || y > 33)
    return 6;
  return x * (y - 32);
}
where y - 32 is not known to be a constant, but [0, 1], which is still
ok to optimize into just normal multiplication, because it never overflows.

Anyway, I'll look into handling it also in gimple-fold.c.

        Jakub

Reply via email to