https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83022
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://reviews.llvm.org/D1
| |10021
--- Comment #16 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually the final LLVM patch which went in is https://reviews.llvm.org/D110021
.
So I think the final check should be the following:
1) same bb, then do it
2) if memset bb's single pred of malloc's and checking `if (ptr)` then do it
3) if memset bb post dominates malloc's bb then do it
4) if malloc's bb ends in `if (ptr)` then if either of the succ bb are post
dominated by the memset bb; then do it.
The first 2 is what LLVM does. 3 allows for:
```
void *r = __builtin_malloc (s);
if (a) *a = r != 0;
__builtin_memset (r, 0, s);
```
4 will allow for the testcase in comment #15. Note 1 is a subset of 3 and 2 is
a subset of 4.
optional 5) probability checks.
But the first 1-4 will almost definitely catch majority of the places where GCC
should optimize even with respect with multiple bb in between. While LLVM only
does 1/2 so extending to do 2/3 is definitely an improvement and still very
fast to do the optimization.