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

            Bug ID: 122309
           Summary: attribute target_clones generates duplicates
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: manu at gcc dot gnu.org
  Target Milestone: ---

It seems GCC is not smart enough to realize that two functions generated by
target_clones() are actually the same.

gcc -Os -ffast-math -march=x86-64-v4 test.c

```c
typedef unsigned char dimension_t;

__attribute__((target_clones("default", "arch=x86-64-v4")))
bool
all_equal_double(const double * restrict a, const double * restrict b,
dimension_t dim)
{
    // The code below is written in a way that helps vectorization.
    // GCC 15 is not able to infer this initialization from ASSUME().
    // unsigned instead of bool to help auto-vectorization.
    unsigned a_eq_b = (a[0] == b[0]) & (a[1] == b[1]);
    for (dimension_t d = 2; d < dim; d++)
        a_eq_b &= (a[d] == b[d]);
    return (bool) a_eq_b;
}

```

This generates two identical functions. It should generate a single function
that is called by the resolver in any case. I would have expect -fipa-icf to
catch this.

This is a contrived example for simplicity. But there may be cases where the
options given in target_clones() actually produce the same code but this is not
evident at a first glance (and may change in newer versions of GCC).

Reply via email to