On Mon, Jun 15, 2026 at 10:22 AM Jeffrey Law
<[email protected]> wrote:
>
>
>
> On 6/14/2026 10:02 AM, Kael Andrew Franco wrote:
> >  From ae75421fd6c7d50e5b1e9aafea2ae3cbcd4ebc1c Mon Sep 17 00:00:00 2001
> > From: Kael Andrew Alonzo Franco <[email protected]>
> > Date: Sun, 14 Jun 2026 06:28:01 -0400
> > Subject: [PATCH] match: For nonnegative X and Y, relax condition on X % Y < 
> > Y to true [PR125737]
> >
> > tree_expr_nonnegative_p covers TYPE_UNSIGNED (type) or when X and Y are 
> > known to be nonnegative.
> >
> > Bootstrapped and tested on x86_64-pc-linux-gnu
> >
> >       PR tree-optimization/125737
> >
> > gcc/ChangeLog:
> >
> >       PR tree-optimization/125737
> >       * match.pd: Use tree_expr_nonnegative_p for X % Y < Y to true.
> >
> > gcc/testsuite/ChangeLog:
> >
> >       PR tree-optimization/125737
> >       * gcc.dg/125737.c: New test.
> Thanks.  I've pushed this to the trunk as well.  I'll note that you're
> checking both types as being non-negative now when previously we just
> checked the first was UNSIGNED.  So your test is both tighter in some
> ways and looser in others.  Regardless it looks good and I've pushed it
> to the trunk.

Oh yes, this is slightly more constraint than needed; it looks like it
was a one for one transformation; that is replace all `TYPE_UNSIGNED
(type)` checking for non-negative on all operands.
In this case we only really need it on the Y operand.
In fact I see LLVM turns ` (a %  b) < b` into `b >= 0` rather than
depending on the inputs being non-negative.
So that is another improvement to the pattern that can be done. for
unsigned it will always be true still.

Thanks,
Andrea

> jeff

Reply via email to