On Wed, Aug 29, 2018 at 05:39:26PM +0100, Vlad Lazar wrote:
> r263591 introduced the following regressions on multiple platforms:
> +FAIL: c-c++-common/torture/builtin-arith-overflow-17.c   -O0  execution test
> +FAIL: c-c++-common/torture/builtin-arith-overflow-17.c   -O2  execution test
> +FAIL: c-c++-common/torture/builtin-arith-overflow-17.c   -O2 -flto  
> execution test
> +FAIL: c-c++-common/torture/builtin-arith-overflow-17.c   -O2 -flto 
> -flto-partition=none  execution test
> +FAIL: c-c++-common/torture/builtin-arith-overflow-p-17.c   -O0  execution 
> test
> +FAIL: c-c++-common/torture/builtin-arith-overflow-p-17.c   -O2  execution 
> test
> +FAIL: c-c++-common/torture/builtin-arith-overflow-p-17.c   -O2 -flto  
> execution test
> +FAIL: c-c++-common/torture/builtin-arith-overflow-p-17.c   -O2 -flto 
> -flto-partition=none  execution test
> 
> The cause for this was that in canonicalize_comparison wi::add was used to 
> add a negative number.  This meant
> that in case of underflow the flag would not have been set.  The solution is 
> to use wi::sub if the immediate
> needs to be decremented.
> 
> The patch fixes the mentioned regressions.
> Bootstrapped and regtested on aarch64-none-linux-gnu and x86_64-pc-linux-gnu.

LGTM, but ChangeLog entry is missing, can you please provide one before I
can ack it?

> diff --git a/gcc/expmed.c b/gcc/expmed.c
> index be9f0ec9011..84f58f540ab 100644
> --- a/gcc/expmed.c
> +++ b/gcc/expmed.c
> @@ -6235,7 +6235,13 @@ canonicalize_comparison (machine_mode mode, enum 
> rtx_code *code, rtx *imm)
>       wrapping around in the case of unsigned values.  If any occur
>       cancel the optimization.  */
>    wi::overflow_type overflow = wi::OVF_NONE;
> -  wide_int imm_modif = wi::add (imm_val, to_add, sgn, &overflow);
> +  wide_int imm_modif;
> +
> +  if (to_add == 1)
> +    imm_modif = wi::add (imm_val, 1, sgn, &overflow);
> +  else
> +    imm_modif = wi::sub (imm_val, 1, sgn, &overflow);
> +
>    if (overflow)
>      return;

        Jakub

Reply via email to