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

--- Comment #14 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #12)
> The following testcase at least reproduces the unsigned multiplication
> issue, but doesn't reproduce the signed multiplication nor division by -1.
> int
> main ()
> {
>   unsigned a = (1U + __INT_MAX__) / 2U;
>   unsigned b = 1U;
>   unsigned c = (a * 2U > b * 2U ? a * 2U : b * 2U) * 2U;
>   if (c != 0U)
>     __builtin_abort ();
>   int d = (-__INT_MAX__ - 1) / 2;
>   int e = 10;
>   int f = (d * 2 > e * 2 ? d * 2 : e * 2) * 6;
>   if (f != 120)
>     __builtin_abort ();
>   int g = (-__INT_MAX__ - 1) / 2;
>   int h = 0;
>   int i = (g * 2 > h * 2 ? g * 2 : h * 2) / -1;
>   if (i != 0)
>     __builtin_abort ();
> }

Ah, the reason it doesn't fail for the f and i cases is that for the signed
type cases, we actually don't create a MIN_EXPR or MAX_EXPR but COND_EXPR which
just compares the vars and performs multiplication only in the COND_EXPR
second/third arguments.
So it is kind of hard trying to make it trigger for the problematic cases where
the recursive calls would extract something.

Will see in full bootstrap/regtest with logging how often does the patch
trigger.

Reply via email to