[Bug ipa/95558] [9/10/11/12 Regression] Invalid IPA optimizations based on weak definition

2022-01-21 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95558

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P2

[Bug ipa/95558] [9/10/11/12 Regression] Invalid IPA optimizations based on weak definition

2022-01-17 Thread hubicka at kam dot mff.cuni.cz via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95558

--- Comment #13 from hubicka at kam dot mff.cuni.cz ---
> Result pure looping 0
> Function found to be pure: foo/4
This is good - we are supposed to find it to be pure and walk all
aliases and update noninterposable ones
> Declaration updated to be pure: foo/4
I have to take look why this happens though.

[Bug ipa/95558] [9/10/11/12 Regression] Invalid IPA optimizations based on weak definition

2022-01-17 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95558

--- Comment #12 from Andrew Pinski  ---
(In reply to Rich Felker from comment #11)
> Are you sure? If pure/const discovery is no longer applied to weak
> definitions, it shouldn't be able to propagate to a non-inlined caller. Of
> course the fix may be incomplete or not working, which I guess we could tell
> from whether it happened prior to or after comment 5. :)

There still looks like there is a bug as shown by taking the original testcase
in comment #0 and using -O2 -fno-inline, you will get:

reclaim_gaps:
ret
...
foo:
ret

Which is still wrong as reclaim should not be considered as pure.

>From *.pure-const:

Starting cycle
  Visiting donate_dummy/0 state:const looping 0
Result const looping 0
Function found not to call free: donate_dummy/0
Starting cycle
  Visiting reclaim/2 state:pure looping 0
Call to __malloc_donate/1 const
Result pure looping 0
Function found to be pure: reclaim/2
Declaration updated to be pure: reclaim/2
Starting cycle
  Visiting reclaim_gaps/3 state:pure looping 0
Call to reclaim/2 state:pure looping:0
Call to reclaim/2 state:pure looping:0
Result pure looping 0
Function found to be pure: reclaim_gaps/3
Declaration updated to be pure: reclaim_gaps/3
Starting cycle
  Visiting foo/4 state:const looping 0
Call to reclaim_gaps/3 state:pure looping:0
Result pure looping 0
Function found to be pure: foo/4
Declaration updated to be pure: foo/4

reclaim, reclaim_gaps and foo are all found as pure. without -fno-inline, we
get some early inlining which causes the difference there.

[Bug ipa/95558] [9/10/11/12 Regression] Invalid IPA optimizations based on weak definition

2022-01-17 Thread bugdal at aerifal dot cx via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95558

--- Comment #11 from Rich Felker  ---
Are you sure? If pure/const discovery is no longer applied to weak definitions,
it shouldn't be able to propagate to a non-inlined caller. Of course the fix
may be incomplete or not working, which I guess we could tell from whether it
happened prior to or after comment 5. :)

[Bug ipa/95558] [9/10/11/12 Regression] Invalid IPA optimizations based on weak definition

2022-01-17 Thread amonakov at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95558

--- Comment #10 from Alexander Monakov  ---
As comment #5 mentioned, it is still broken, you just need -fno-inline in
addition to -O2 for the original testcase. Andrew's remark is quite useful for
situations like this, you know :)

[Bug ipa/95558] [9/10/11/12 Regression] Invalid IPA optimizations based on weak definition

2022-01-17 Thread bugdal at aerifal dot cx via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95558

--- Comment #9 from Rich Felker  ---
Can you provide a link to the commit that might have fixed it? I imagine it's
simple enough to backport, in which case I'd like to do so.

[Bug ipa/95558] [9/10/11/12 Regression] Invalid IPA optimizations based on weak definition

2022-01-17 Thread hubicka at kam dot mff.cuni.cz via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95558

--- Comment #8 from hubicka at kam dot mff.cuni.cz ---
> > Do weak aliases fall under some implicit ODR here?
> 
> The whole definition of "weak" is that it entitles you to make a definition
> that will be exempt from ODR, where a non-weak definition, if any, replaces 
> it.

I fixed recently bug in pure-const discovery which made us to add
attributes to weaks while it should not, so perhaps this bug is gone.
For non-inline functions we should handle those as interposable.
Concerning warning, I we make difference between may and must warnings.
I think this is still useful do be diagnosed for user to consider
(perhaps there is a reason why all overwritters has to be weak), so I
think we should porduce may form of warning.

I will take a look.

[Bug ipa/95558] [9/10/11/12 Regression] Invalid IPA optimizations based on weak definition

2022-01-17 Thread bugdal at aerifal dot cx via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95558

--- Comment #7 from Rich Felker  ---
> Do weak aliases fall under some implicit ODR here?

The whole definition of "weak" is that it entitles you to make a definition
that will be exempt from ODR, where a non-weak definition, if any, replaces it.

[Bug ipa/95558] [9/10/11/12 Regression] Invalid IPA optimizations based on weak definition

2022-01-17 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95558

--- Comment #6 from Richard Biener  ---
Honza?  What's your stance here?  Do weak aliases fall under some implicit ODR
here?

[Bug ipa/95558] [9/10/11/12 Regression] Invalid IPA optimizations based on weak definition

2021-09-21 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95558

Andrew Pinski  changed:

   What|Removed |Added

  Known to fail||4.7.1
  Known to work||4.5.3, 4.6.4
   Target Milestone|--- |9.5
Summary|Invalid IPA optimizations   |[9/10/11/12 Regression]
   |based on weak definition|Invalid IPA optimizations
   ||based on weak definition

--- Comment #5 from Andrew Pinski  ---
Note you need -fno-inline to produce the issue these days.
Plus it is a regression from GCC 4.6.