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

            Bug ID: 125738
           Summary: `a/b==0` can be simplified into a > b when a and b are
                    non-negative
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: easyhack, missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
int
f (unsigned short a, unsigned short b) {
  int aa = a;
  int bb = b;
  int c = aa / bb;
  return c == 0;
}
```
This should be optimized to `a >b`
But current is not because the pattern:
```
/* Transform:
   (X / Y) == 0 -> X < Y if X, Y are unsigned.
   (X / Y) != 0 -> X >= Y, if X, Y are unsigned.  */
(for cmp (eq ne)
     ocmp (lt ge)
 (simplify
  (cmp (trunc_div @0 @1) integer_zerop)
  (if (TYPE_UNSIGNED (TREE_TYPE (@0))
       /* Complex ==/!= is allowed, but not </>=.  */
       && TREE_CODE (TREE_TYPE (@0)) != COMPLEX_TYPE
       && (VECTOR_TYPE_P (type) || !VECTOR_TYPE_P (TREE_TYPE (@0))))
   (ocmp @0 @1))))
```

Only checks TYPE_UNSIGNED rather than if both @0 and @1 are non-negative.

Reply via email to