Hi Jakub,

On Thu, Nov 29, 2018 at 03:00:22PM +0100, Jakub Jelinek wrote:
> vec_add/sub of with vector unsigned args is lowered to a builtin which
> has vector signed args and therefore if not -fwrapv it is undefined if
> signed integer overflow occurs in those vectors.
> 
> The following patch fixes it to make sure that those builtins are folded
> to PLUS/MINUS_EXPR done on unsigned vectors instead, so there is no UB.
> If it makes it through to RTL expansion, it makes no difference, but
> for UBSan it matters a lot and also I'd say if e.g. we'd extract just one
> scalar from the resulting vector, we'd optimize it just to a scalar +/- and
> could very well optimize based on lack of UB.
> 
> I've looked at a couple of other builtins, but e.g. with vec_mul* couldn't
> trigger anything problematic.
> 
> Bootstrapped/regtested on powerpc64{,le}-linux, ok for trunk?

Okay for trunk, and backports too if you want any.  Thanks!


Segher


> 2018-11-29  Jakub Jelinek  <ja...@redhat.com>
> 
>       PR target/88234
>       * config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): For
>       vec_add and vec_sub builtins, perform PLUS_EXPR or MINUS_EXPR
>       in unsigned_type_for instead of vector integral type where overflow
>       doesn't wrap.
> 
>       * gcc.dg/ubsan/pr88234.c: New test.

Reply via email to