This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix vec_{add,sub} rs6000_gimple_fold_builtin folding (PR target/88234)
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: David Edelsohn <dje dot gcc at gmail dot com>, gcc-patches at gcc dot gnu dot org
- Date: Thu, 29 Nov 2018 08:14:25 -0600
- Subject: Re: [PATCH] Fix vec_{add,sub} rs6000_gimple_fold_builtin folding (PR target/88234)
- References: <20181129140022.GI12380@tucnak>
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 <jakub@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.