https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104356

--- Comment #34 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> For the X / bool_range_Y is X. case I think just !flag_non_call_exceptions
> would be better.  If @1 has boolean range and is known to be non-zero, it is
> known to be 1, so we should be optimizing it elsewhere, that is the constant
> case.

OK, adjusted and successfully tested on x86-64/Linux.

> path isolation is already guarding is_divmod_with_given_divisor calls with
> !cfun->can_throw_non_call_exceptions.

Indeed.

> Can you try to rewrite the
> unsigned                                                                    
> foo (unsigned x, unsigned y)                                                
> {                                                                           
>   if (x >= 2)                                                               
>     return 0;                                                               
>   if (x == 1)                                                               
>     y += 4;                                                                 
>   return y / x;                                                             
> }                                                                           
> 
> testcase I've posted into Ada and see if it will optimize away the division
> in evrp or vrp?

For:

with System.Unsigned_Types; use System.Unsigned_Types;

function F (X, Y : Unsigned) return Unsigned is
begin
  if X >=2 then
    return 0;
  elsif X = 1 then
    return 2 * Y;
  else
    return Y / X;
  end if;
end;

I get with -O2 -gnatp:

_ada_f:
.LFB1:
        .cfi_startproc
        cmpl    $1, %edi
        ja      .L4
        je      .L6
        ud2
        .p2align 4,,10
        .p2align 3
.L4:
        xorl    %eax, %eax
        ret
        .p2align 4,,10
        .p2align 3
.L6:
        leal    (%rsi,%rsi), %eax
        ret

Reply via email to