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

--- Comment #18 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Lénárd Szolnoki from comment #11)
> (In reply to Andrew Pinski from comment #10)
> > So if I understand this, the general jist is valgue linkage functions needs
> > to be treated the same as weak functions when it comes to any IPA
> > optimizations except for inlining?
> 
> And cloning. If the function is cloned then all other IPA optimizations are
> also fair play.

No because what GCC is doing in the original testcase is cloning
check_arg_1_value for 1/2 from the call of depends_on_unpsecified_content. 
This is why I said cloning is can't be done.

So NO cloning is not valid unless it is from a non vague call.

You can see that with:
```

struct Counter {
  int count;
public:
  [[gnu::always_inline]]
  int nextCount() { return ++count; }
};

// Will return true if args are evaluated R => L.
[[gnu::used, gnu::noinline]]
inline bool
check_arg_1_value (int a, int b)
{
  return a == 2;
}

// Will abort if x == 0 and args are evaluated R => L.
[[gnu::used, gnu::noinline]]
inline int
depends_on_unpsecified_content (int x)
{
  Counter c = {0};
  if (check_arg_1_value (1, 2)
      && x == 0)
    __builtin_abort();

  return x;
}

int
main ()
{
   if (depends_on_unpsecified_content(0) == 0)
     return 5;
  return 20;
}
```
Compile with -fno-inline and you will see:
check_arg_1_value(int, int) [clone .constprop.0]:
        xorl    %eax, %eax
        ret

In the GCC case clones stuff agressively because that is how IPA CP, etc. work.

Reply via email to