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

            Bug ID: 122186
           Summary: single_use is too much on some match patterns
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
            Blocks: 118557
  Target Milestone: ---

Take:
```
char f(char *a, __SIZE_TYPE__ b)
{
  char *c = a + b;
  if (c != a)
    return *c;
  return 0;
}
char f1(char *a, __SIZE_TYPE__ b)
{
  char *c = a + b;
  if (b != 0)
    return *c;
  return 0;
}
```

These should produce the same code but don't currently.
The problem is the pattern uses single_use:
```
 (simplify
  (op:c (nop_convert?@3 (pointer_plus@2 (convert1? @0) @1)) (convert2? @0))
  (if (tree_nop_conversion_p (TREE_TYPE (@2), TREE_TYPE (@0))
       && tree_nop_conversion_p (TREE_TYPE (@3), TREE_TYPE (@0))
       && (CONSTANT_CLASS_P (@1) || (single_use (@2) && single_use (@3))))
   (op @1 { build_zero_cst (TREE_TYPE (@1)); }))))
```
Which seems to produce worse code here.

This one is reduced from PR 118557.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118557
[Bug 118557] -Wstringop-overflow false positive for span on array/string_view
due to the vectorizer

Reply via email to