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

            Bug ID: 125754
           Summary: `(a > 1) ? 0 : (convert?)a` -> `(cast)(a==1)` can be
                    done if a is signed and nonnegative
           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 t = (aa > 1) ? 0 : aa;
  return t;
}

unsigned
g (unsigned short a, unsigned short b) {
  unsigned aa = a;
  unsigned bb = b;
  unsigned t = (aa > 1) ? 0 : aa;
  return t;
}
```
These 2 should produce the same code but does not currently because the
pattern:
```
(simplify
 (cond (gt @0 integer_onep@1) integer_zerop (convert? @2))
 (if (TYPE_UNSIGNED (TREE_TYPE (@0))
      && bitwise_equal_p (@0, @2))
  (convert (eq @0 @1))
 )
)
```

Just checks TYPE_UNSIGNED rather than checking the nonnegativeness of @0.

Reply via email to